Results 1 to 2 of 2

Thread: Indexed properties and java.util.Set

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Warsaw, Poland
    Posts
    33

    Default 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.

    Artur

  2. #2
    Join Date
    Sep 2004
    Posts
    5

    Default

    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">
    <input
    type="checkbox" name="${status.expression}"
    <c:if test="${status.value}">checked</c:if>
    >
    </spring:bind>
    </c:forEach>

    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.

Similar Threads

  1. Binding String[] to java.util.Set
    By plethora in forum Web
    Replies: 9
    Last Post: Feb 26th, 2010, 06:23 AM
  2. How to bind a java.util.Set
    By rsi in forum Web
    Replies: 6
    Last Post: May 3rd, 2005, 02:38 AM

Posting Permissions

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