4

I have a scenario where in I'm suppose to generate same form multiple times. My application is based on spring 3.0 framework.

Scenario: Basically I'm designing this application for transportation company, where there is a requirement to schedule the loads )which driver carries which load and when and from which origin to which destination). Now, the problem is some times loads will not be directly delivered from origin to destination, there will splits in delivery, for example, one driver will carry loads up to some point from origin and again another driver carries it from that point to destination. But the number of splits may vary very time.

So i need to generate multiple form dynamically based on number of splits to schedule the loads like

Enter first splits information
--------------------------------
form1
----------------------------------


Enter second splits information
--------------------------------
form2
-------------------------------

submit button
Bruno Croys Felthes
  • 1,183
  • 8
  • 27
  • Post what you tried, then we can help you... Is there so many options to do it... – Bruno Croys Felthes Feb 05 '13 at 02:48
  • Looks like this need to be done in the client side, using javascript, using a library like http://jquery.com/ – Arun P Johny Feb 05 '13 at 03:25
  • Probably you will get the split info from DB or some server side logic. Based on that prepare a list of Schedule DTO's and loop through it and render. If that schedul split details keep changing use jquery to ajaxify the rendering part. – K. Siva Prasad Reddy Feb 05 '13 at 05:55

2 Answers2

4

You can do something as below,

First in any of your jquery function in your jsp page add following code,

for(var i=0; i<lcount;i++){ //lcount is number of splits.               
$('#tload'+i).load('url of controller class that helps in loading form');
}

Write some divs in same jsp page with id as 'tload1','tload2','tload3' so on.

<div id="tload1"></div>
<div id="tload2"></div>
<div id="tload3"></div>
............
............
so on

whenever returning from your controller return to jsp page that contains iframe which loads your form. By Using .load() function as shown above will automatically load iframe containing your forms into respective div tags.That's it, your problem is sloved.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Kishan_KP
  • 4,488
  • 6
  • 27
  • 46
  • This was just like a great piece of hint for me. Thanks alot, it works this way. –  Mar 27 '13 at 14:20
0

Here are some options:

  1. Pure JavaScript approach - I would use a JS library, like jQuery, but basically have JS that will add the needed sections to the form. See my answer here.
  2. Round-trip approach - Have JSTL build the form using a list of "splits" in the model attribute. When the user hits "Add Split", you make a call to the same URL, passing in an optional parameter to indicate how many splits should be there. It adds a new one to the list are returns back to your view

I personally like the first one, as it reduces the number of calls to the backend. The one thing you have to watch for is if you have an Add and Remove button. If you remove stuff from a list that is backed by a map/list in your model attribute, you need to "clean out" those entries else they could still be there when you finally submit your form.

Community
  • 1
  • 1
CodeChimp
  • 8,016
  • 5
  • 41
  • 79