Results 1 to 9 of 9

Thread: newbie: binding problems / indexed properties / checkbox

  1. #1
    Join Date
    Sep 2005
    Posts
    26

    Default newbie: binding problems / indexed properties / checkbox

    hello,

    I'm very new to spring and webflow and stumble over my first problem.
    I hope you have a minute or two and can help me :-)

    My form object has a collection filled with CodedText items

    pseudo code:
    class CodedText {
    code
    text
    }

    At the (JSP) view I display this list:

    <c:forEach var="type" items="${order.types}" varStatus="s">
    <tr><td>
    <spring:bind path="order.types[${s.index}].code">
    <input type="checkbox"
    name="${status.expression}"
    value="${status.value}"/>
    </spring:bind>
    </td>
    <td>
    <c:out value="${type.text}"/> (<c:out value="${type.code}"/>)
    </td>
    </tr>
    </c:forEach>

    This list is prefixed with a checkbox. I want to collect to users choice, but can't get the binding to work proberly :cry:

    Questions:
    - How should I bind the users choice ?
    - How could I redisplay the page and show the current users choice ?

    TIA, leif

  2. #2
    Join Date
    Sep 2005
    Posts
    26

    Default

    another day, another way :lol:

    I fixed my problem :!:

    I created an object that 'holds' my object (item) and has an isSelected flag.

    Next, I had the problem that unchecked checkboxes are not submitted by HTML. To solve this I found a thread and a good comment from user yatesco

    WebDataBinder sets all propertys to empty for which there is a parameter called "_[propertyName]".

    This works for all properties, not just checkboxes
    So here is my JSP code:

    Code:
    <c&#58;forEach var="type" items="$&#123;order.test&#125;" varStatus="s">
    <tr>
        <td>
        <spring&#58;bind path="order.test&#91;$&#123;s.index&#125;&#93;.selected">
             <input type="checkbox" name="$&#123;status.expression&#125;" value="true" <c&#58;if test="$&#123;status.value&#125;">checked="checked"</c&#58;if> />
             <input type="hidden" name="_<c&#58;out value="$&#123;status.expression&#125;"/>"> 
        </spring&#58;bind>
        </td>
        <td><c&#58;out value="$&#123;type.item.text&#125;"/> &#40;<c&#58;out value="$&#123;type.item.code&#125;"/>&#41;</td>
    </tr>
    </c&#58;forEach>

    If you have better ideas, let me know.
    Thanks in advance, Leif

  3. #3
    Join Date
    Oct 2005
    Location
    Amsterdam
    Posts
    81

    Default For a java.util.Set

    Hi, I am having the same issue.

    I guess your solution would work fine if your FormBackingObject has a List (or any other indexed collection...) as the backing property, what can you do if you have a java.util.Set? Or is that actually possible at all (since the Set is not indexed)?

    Any workarounds?

    Code:
    Invalid property 'serviceLines[0]' of bean class [domain.ProjectCredential]: Cannot get element with index 0 from Set of size 0, accessed using property path 'serviceLines[0]'
    Nicolas

  4. #4
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Yes you can use a set apparantely. Do a search for http://www.springframework.org/docs/...ionEditor.html
    on these forums. A couple of people have asked about this in the past few weeks.

  5. #5
    Join Date
    Oct 2005
    Location
    Amsterdam
    Posts
    81

    Default

    Hi Yatesco,

    I guess I was one of them :-). As you correctly pointed out, the submission works fine, however, if any validation happens, it doesn't "remember" the checked-checkboxes... (I was actually going through this testing to answer your question on this post: http://forum.springframework.org/sho...=20503&page=3).

    The code that is posted here would definitely not work with a Set as it is not indexed.

    Code:
    <c:forEach var="type" items="${order.test}" varStatus="s">
    <tr>
        <td>
        <spring:bind path="order.test[${s.index}].selected">
             <input type="checkbox" name="${status.expression}" value="true" <c:if test="${status.value}">checked="checked"</c:if> />
             <input type="hidden" name="_<c:out value="${status.expression}"/>"> 
        </spring:bind>
        </td>
        <td><c:out value="${type.item.text}"/> (<c:out value="${type.item.code}"/>)</td>
    </tr>
    </c:forEach>
    I foolishly used Set's since they're widely used in the Hibernate examples. I was wondering whether somebody had actually done it and if it was possible, since there's no index on a Set.

  6. #6
    Join Date
    Aug 2004
    Posts
    1,905

  7. #7
    Join Date
    Aug 2004
    Location
    Paris
    Posts
    43

    Default

    Nicolas,

    Maybe, you could try this code, and use your CustomCollectionEditor. This assume that your PropertyEditor will handle correctly a serie of inputs in your form named identicaly. It also assume that the test myArchiDomain == domain is correctly evaluated by JSTL when the objects are not primitives.
    This is far better to use List, as you will be able to use ProperyEditor for elements of your list, which is not the case here.

    Code:
    <spring:bind path="project.architectureDomains">
    <c:forEach items="${domains}" var="domain" varStatus="loopStatus">
           	   <input type="hidden" name="_<c:out value="${status.expression}"/>">
    	   <input type="checkbox" name="<c:out value="${status.expression}"/>" value="<c:out value='${domain.id}' />"
         <c:forEach items="${project.architectureDomains}" var="myArchiDomain">  
                <c:if test="${myArchiDomain == domain}">checked</c:if>
         </c:forEach>
         <c:out value="${domain.name}" /><br>
    </c:forEach>
    </spring:bind>

  8. #8

    Default Binding Multiple value with CheckBox

    Hi all,

    I got some information about binding list values when using Checkbox.
    But in the below mentioned code, can please anyone tell me,
    how to create checked property when binding the list with spring

    <c:forEach items="${myDataModel.drivers}" var="driver" varStatus="loopStatus">

    <spring:bind path="myDataModel.drivers[${loopStatus.index}].checked">
    <input class="checkbox" type="checkbox"
    name ="<c:out values = "_${status.expression}"/>"
    value = "true" <c:if test="${status.value}">CHECKED</c:if> >
    </spring:bind>
    </c:forEach>

    Please help me
    Thanks in advance
    Shilpa

  9. #9

    Default Binding multiple value with checkbox

    Quote Originally Posted by strug
    hello,

    I'm very new to spring and webflow and stumble over my first problem.
    I hope you have a minute or two and can help me :-)

    My form object has a collection filled with CodedText items

    pseudo code:
    class CodedText {
    code
    text
    }

    At the (JSP) view I display this list:

    <c:forEach var="type" items="${order.types}" varStatus="s">
    <tr><td>
    <spring:bind path="order.types[${s.index}].code">
    <input type="checkbox"
    name="${status.expression}"
    value="${status.value}"/>
    </spring:bind>
    </td>
    <td>
    <c:out value="${type.text}"/> (<c:out value="${type.code}"/>)
    </td>
    </tr>
    </c:forEach>

    This list is prefixed with a checkbox. I want to collect to users choice, but can't get the binding to work proberly :cry:

    Questions:
    - How should I bind the users choice ?
    - How could I redisplay the page and show the current users choice ?

    TIA, leif
    In the above code, can you please tell me where i need to create code code when binding list object.

    Thanks
    Shilpa

Similar Threads

  1. FlowExecutionStorage in a DB
    By cacho in forum Web Flow
    Replies: 7
    Last Post: Oct 19th, 2009, 03:36 PM
  2. Binding composite properties with DataBinder
    By dhewitt in forum Architecture
    Replies: 16
    Last Post: Jun 1st, 2007, 06:22 AM
  3. Replies: 0
    Last Post: Jan 11th, 2005, 10:45 PM
  4. Indexed properties and java.util.Set
    By karaznie in forum Web
    Replies: 1
    Last Post: Sep 20th, 2004, 03:55 AM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 PM

Posting Permissions

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