Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring List Binding in Form
    text
    copied!<p>I'm trying to bind a list/arraylist/hashmap/etc of custom objects to my form in JSP using Spring. Right now, the controller creates a Map of the two lists (Boolean list and custom object list) in <code>referenceData()</code>, and provides it to the form which uses those values to populate the fields. The values are initialized from a MySQL database using Hibernate, and all that works fine. The list is a known length before the form is initialized, so that part is easier. Now what I'd like to do is correctly bind those objects in the form, so that when there are changes made, I can detect that in <code>onSubmit()</code> (or wherever is appropriate), and update the database accordingly. I can't seem to bind them correctly in the form so that I can see changes made. I tried just using a list of the form fields as the model, but even that wasn't working correctly. Do I just need to inject the list in a particular way? Any ideas or examples here? Any help would be greatly appreciated.</p> <p>UPDATE: At Ralph's request here is the solution I used: In my data object class, I lazy loaded a map using <code>MapUtils.lazyMap()</code>, with a String key and other custom object value. The other custom object is just a class that contains <code>List&lt;String&gt;</code> and getters/setters. In the corresponding .jsp file, I just nest several loops to loop through the keys first using <code>loop.current.key</code> and then <code>loop2.current.value.paramsList</code> to loop through the values for that key. This was not really what I asked for in my original post, as I was looking for a more general solution, and the lazy loading pointed me in the right direction.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload