Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Dynamic population of form fields upon combo selection SPRING MVC

  1. #1
    Join Date
    Jun 2011
    Posts
    11

    Default Dynamic population of form fields upon combo selection SPRING MVC

    have a Drop down list and a Listbox. What I want to do is to populate data to the listBox when an option is selected from the Drop Down list.

    Could you tell me how can I achieve this in a simple manner?

    The problems that I had

    Couldn't save nested objects in a spring:form
    Couldn't update the listbox items when dropdown onchange event fired
    Hard to know where to store a static array in an HTML web page
    Had to redirect to the server and there I had lots of problems it so tires me when I have to do round trip for a small thing
    Your helps will be much appreciated Cheers

  2. #2
    Join Date
    May 2008
    Location
    Haddonfield, NJ 08033
    Posts
    46

    Default Use ajax

    This is quite simple. Use the Ajax lib of your choice. Try jQuery if you don't have one already.

  3. #3
    Join Date
    Dec 2010
    Posts
    175

    Default

    Using jQuery it would be very simple. For example if your dropdown list id is 'products' then you can write a jQuery as:

    Code:
    $(document).ready(function() {
     	$('#products').click(function() {
                   //make a call to service which returns the list.
    	});
    });
    For an example on how to integrate Spring + JSON + jQuery you can find many examples here is one...
    http://springdiaries.blogspot.com/20...ng-mvc-3x.html

  4. #4
    Join Date
    Jun 2011
    Posts
    11

    Default

    Thank you guys, never tried JQuery before so I didn't know I could do populating with JQuery.
    I will check it out.


    Cheers!!!

  5. #5
    Join Date
    May 2008
    Location
    Haddonfield, NJ 08033
    Posts
    46

    Default

    Actually, here is an article that offers a fully working Maven project.
    It uses jQuery and Spring MVC 3 to populate two selects: states and cities.
    The states is populated at load time and the cities is populated when you select a state.
    It has unit and integration tests via jetty and Selenium 2.

  6. #6
    Join Date
    Jun 2011
    Posts
    11

    Default

    The example in the website is pretty new, uses spring mvc 3. It is hard to find examples like this one. Thanks for sharing the website, it will be very useful for me.

    Cheers...

  7. #7

    Default

    Hi,

    Json works fine here, and I can fetch data no problem.
    Altering dropdown lists (selects or options in selects) does not, I dont seem to be able to update the results.

    Im using spring MVC with Roo generated code and I just added some javascript to handle changing the contents of the dropdown list.

    Any ideas ?

    Regards,
    Emil

  8. #8
    Join Date
    May 2008
    Location
    Haddonfield, NJ 08033
    Posts
    46

    Default

    Is there any reason that the aforementioned article and complete example doesn't work for you?

  9. #9

    Default

    Well it uses different tags than what I have in spring MVC.

    Ive tried at least 5 different jquery and dojo/dijit examples and most of them end with

    $('#usStates').html(html);
    or
    setting innerHTML of the destination object, but when I try that it simply doesnt work, no error I just dont get the results.

    I tried modifying the options list of the current select item and that didnt work.

    Do you know an example of this that works with Roo generated controllers ? that is Spring MVC ? if so please send me a link

    Regards,
    Emil

    p.s. I will try futher to integrate this example into my Spring MVC code/controllers and see if I can get it to work

  10. #10
    Join Date
    May 2008
    Location
    Haddonfield, NJ 08033
    Posts
    46

    Default

    Quote Originally Posted by emil2010 View Post
    Well it uses different tags than what I have in spring MVC.
    So you're not using HTML tags nor Spring MVC's core and form tags? That's what the example uses along with jQuery. And it's all explained in the article.

    We're not mind readers so if you want further help you need to post your broken code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •