Announcement Announcement Module
No announcement yet.
Indexed properties and java.util.Set Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Indexed properties and java.util.Set

    I'm currently trying to migrate my project from struts to spring MVC. Simple things were very easy to port, but I've problem with more advanced topics.

    My first problem is how can I bind indexed properties in spring. I've read in documentation that's possible but can't find any example how to do this.

    My second question is if is there possible to bind 'indexed' (I know, Set has no order) properties to java.uti.Set. Suppose I have beans

    public class Foo {
    Set bars;

    public class Bar {
    boolean valid;

    How can I bind values of Set ('dynamically')? Of course i can always do it myself in onBind - but I wonder if there is maybe something embedded in spring which does it already.


  • #2
    You can do it using spring bind tag. First of all yoy must prepare a bean with field containing your Set - Foo class. Let command name be "foo".
    Then in JSP, using JSTL iteration:

    <c:forEach vars="foo.bars" var="bar" varStatus="fooStatus">
    <spring:bind path="foo.bars[${fooStatus.index}].valid">
    type="checkbox" name="${status.expression}"
    <c:if test="${status.value}">checked</c:if>

    I think you will have to prepare some mechanism for binding this set on submission based on your implementation of PropertyEditorSupport since (as you had noticed) Set has no indices.
    I hope this could helpe you somehow.