PDA

View Full Version : ReferenceData Binding problem


kermie5000
Jul 27th, 2005, 11:33 AM
In my referenceData, I create three different Collections to put on the map I return to the jsp. I populate these collections by calling a DAO. I want three distinct dropdowns, but I want them to have the same values in the dropdowns.

Collection toys = null;
toys = getDropdownValues("from Toys");

Collection toys2 = null;
toys2 = getDropdownValues("from Toys");

refData.put("toys", toys);
refData.put("toys2", toys2);
return refData;

When I hit submit, however, it does not bind based on what I select in the distinct dropdowns. One of the dropdowns sets the values for all the dropdowns. I have tried changing the c:foreach "var" and "items" properties to be different, but it seems like the problem is that the same objects are in every dropdown. Any ideas for how I can get around this, or do I need to have different objects in my dropdowns?

Thanks for any help!

katentim
Jul 27th, 2005, 06:33 PM
One of the dropdowns sets the values for all the dropdowns.
This sounds like an HTML issue. Are you using a different name for each of the dropdowns? Maybe post the command object and the JSP.

Colin Yates
Jul 28th, 2005, 05:48 AM
I want three distinct dropdowns, but I want them to have the same values in the dropdowns.

and
but it seems like the problem is that the same objects are in every dropdown

I am confused, do you want the same objects in each drop down or not ;)

kermie5000
Jul 28th, 2005, 01:27 PM
Yes. I do want the same objects in different dropdowns. But I want to be able to select different ones and bind them to different properties. Right now, it appears that one overwrites the other.

<spring:bind path="command.toy.id">
<FONT color="red">
<B><c:out value="${status.errorMessage}"/></B>
</FONT>

<select name="<c:out value="${status.expression}"/>">
<c:forEach var="toy" items="${toys}">
<c:if test="${command.toy.id == toy.id}">
<OPTION selected="<c:out value="${command.toy.id}"/>"
value="<c:out value="${command.toy.id}"/>">
<c:out value="${toy.name}"/></OPTION>
</c:if>
<c:if test="${command.toy.id != toy.id}">
<OPTION value="<c:out value="${toy.id}"/>">
<c:out value="${toy.name}"/></OPTION>
</c:if>
</c:forEach>
</select>
</spring:bind>

<spring:bind path="command.toy2.id">
<FONT color="red">
<B><c:out value="${status.errorMessage}"/></B>
</FONT>

<select name="<c:out value="${status.expression}"/>">
<c:forEach var="toy" items="${toys2}">
<c:if test="${command.toy2.id == toy.id}">
<OPTION selected="<c:out value="${command.toy2.id}"/>"
value="<c:out value="${command.toy2.id}"/>">
<c:out value="${toy.name}"/></OPTION>
</c:if>
<c:if test="${command.toy2.id != toy.id}">
<OPTION value="<c:out value="${toy.id}"/>">
<c:out value="${toy.name}"/></OPTION>
</c:if>
</c:forEach>
</select>
</spring:bind>

Should this work? Remember, both toys and toys2 are collections that hold the same objects. Could it be the status.expression messing things up?

Colin Yates
Jul 28th, 2005, 02:26 PM
Looks fine, can you post the rendered html just to make sure.... Also how are you binding? What does your controller and formBackingObject look like?

kermie5000
Jul 28th, 2005, 03:01 PM
I'm not binding anything explicitly, I'm just letting it do it automatically. Should I be doing more?

I'll post the rendered HTML in a little bit.

kermie5000
Sep 16th, 2005, 01:43 PM
<select name="toy.id">
...
</select>

<select name="toy2.id">
...
</select>

I am just using the default binding...but it binds the same value to both, even if I pick different values. Seems to bind to both whatever you pick in the last one on the page.

kermie5000
Sep 19th, 2005, 12:12 PM
Thanks for your help on this one.

I figured out that when I was instantiating my nested objects in the formBackingObject, I was only instantiating one, and copying that instantiated object for both. (Ha, ha, I thought I was being efficient.) Somewhere in the binding process, one overwrites the other, and that's where my problem was occurring.

With each nested object having its own instantiated object, the binding works as expected. If anyone is having problems with binding, you can always look into binding manually in the onBind() method since you can grab the parameters out of your request object.