PDA

View Full Version : Bind Tag Issue


tiago182
Feb 10th, 2006, 11:22 AM
Hello again,

I already could use the <spring:bind/> tag for binding text fields and checkboxes, but I've got no good results trying with combo-boxes, because the selected value isn't bound to my command object. I mean, after posting, AddProductForm.category comes null. Bellow follows what I've done:

public class AddProductForm {
private Category category = null;
private Collection<Category> availableCategories = new ArrayList();
// a bunch of other fields...
/* regular getters and setters */
}

<spring:bind path="command.category">
<select class="combo" name="<c: out value="${status.expression}"/>">
<c:forEach items="${command.availableCategories}" var="availableCategory">
<option value="<c: out value="${availableCategory}" />"><c: out value="${availableCategory}" /></option>
</c:forEach>
</select>
</spring:bind>

Can somebody tell me what's wrong with this?

Thanks in advance!

Colin Yates
Feb 10th, 2006, 11:26 AM
Check out http://forum.springframework.org/showthread.php?t=17646&highlight=checkboxes

Essentially; you need to register a property editor.

tiago182
Feb 10th, 2006, 11:56 AM
Does it apply to combo-boxes?

I didn't see how it fits, since I'm binding a couple of checkboxes already without using a property editor, so I guess it's not the point.

Colin Yates
Feb 10th, 2006, 01:58 PM
The point is that your setter is of type Category so you need to register a property editor for that Class :)

Nothing to do with checkboxes; merely an example of how to use propertyEditors.

tiago182
Feb 14th, 2006, 08:56 AM
Thanks again Yatesco, it's ok now. I'm using PropertyEditors and now I understand how it works.