Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Multiple select value and spring:bind

  1. #11

    Default

    In my jsp pages i just put a select without spring.

    It works fine for me this is the old methode simple request parameters, convert in the bind methode to object,

    Try it and tell me if it works ;-)

    Fabien

  2. #12
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default

    This works, but I prefer to keep the <spring:bind> so I preceded the <input> names with a "_" so Spring does not see them while binding. This is not really elegant, but it works.

    I think the Spring Team should modify the bind method to pass a string array to a custom editor when multiple form parameters with the same name are posted. Now we could do our stuff in regular propertyEditors.

    Uze

  3. #13

    Default customeditor

    Agree !

    I like to make a customeditor in order to avoid a string[] to objects and objects to string[] conversion (or encapsulate this conversion) ?

    Do u kown a sample ?

    I going to sleep now it's late... see u soon,

    Fabien

  4. #14

    Default Please ....

    Hi,

    Always no way for this ?

    Thanks,

    Fabien.

  5. #15

    Default

    Quote Originally Posted by uze
    This works, but I prefer to keep the <spring:bind> so I preceded the <input> names with a "_" so Spring does not see them while binding. This is not really elegant, but it works.

    I think the Spring Team should modify the bind method to pass a string array to a custom editor when multiple form parameters with the same name are posted. Now we could do our stuff in regular propertyEditors.

    Uze
    Check out this JIRA issue:
    http://opensource.atlassian.com/proj...browse/SPR-552

  6. #16
    Join Date
    Aug 2004
    Location
    Paris
    Posts
    43

    Default

    Here is a nice way to do that, all with pure spring tags :



    you need a property checked (Boolean) in your driver object.

    Code:
    <c&#58;forEach items="$&#123;myDataModel.drivers&#125;" var="driver" varStatus="loopStatus"> 
    
    <spring&#58;bind path="myDataModel.drivers&#91;$&#123;loopStatus.index&#125;&#93;.checked"> 
    	<input class="checkbox" type="checkbox"
                name ="<c&#58;out values = "_$&#123;status.expression&#125;"/>"
                value = "true" <c&#58;if test="$&#123;status.value&#125;">CHECKED</c&#58;if> >
    </spring&#58;bind>
    
    </c&#58;forEach>
    That will bind directly to your list, the checkbox. [/code]

  7. #17
    Join Date
    Sep 2004
    Location
    Boston, US
    Posts
    130

    Default

    Thats for multiple checkboxes. Here's what I did to bind to the muliple select element.

    Code:
    <spring&#58;bind path="equipmentGroupForm.selectedEquipmentGroups">
       <select name="<c&#58;out value="$&#123;status.expression&#125;"/>"  multiple>
       <c&#58;forEach var="equipmentGroup" items="$&#123;equipmentGroups&#125;">  
       <c&#58;out value="$&#123;status.value&#125;" />
    <%
        String equipmentGroup = &#40;&#40;EquipmentGroup&#41;pageContext.getAttribute&#40;"equipmentGroup"&#41;&#41;.getName&#40;&#41;;
        EquipmentGroupForm form = &#40;EquipmentGroupForm&#41;request.getAttribute&#40;"equipmentGroupForm"&#41;;
        Boolean eg_selected =Boolean.valueOf&#40;form.isEquipmentGroupSelected&#40;equipmentGroup&#41;&#41;;
        pageContext.setAttribute&#40;"eg_selected", eg_selected&#41;;
    %>
    
        <option <c&#58;if test="$&#123;eg_selected&#125;">selected</c&#58;if> value="<c&#58;out value="$&#123;equipmentGroup.name&#125;"/>">
        <c&#58;out value="$&#123;equipmentGroup.name&#125;"/>
    </option>
    </c&#58;forEach>
    </select>
    </spring&#58;bind>
    Regards,
    Sanjiv

  8. #18

    Default

    Quote Originally Posted by olivier View Post
    Here is a nice way to do that, all with pure spring tags :



    you need a property checked (Boolean) in your driver object.

    Code:
    <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>
    That will bind directly to your list, the checkbox.

    May i know how u collect back those "checked" check boxes into controller and submit to JDBC?

  9. #19

    Default spring binding issue: binding the indexed element (format[${loopStatusF does not work

    Hello,
    I am having an issue binding 'format' elements in beneath code.


    I have a double loop:
    The first loop binds the attribute 'docbase_name' in the 'repository' loop:
    docshifterReceiverConfig.configuration.repositorie s.repository[${loopStatusRepo.index}].docbase_name
    Works fine.

    The second nested loop:
    docshifterReceiverConfig.configuration.repositorie s.repository[${loopStatusRepo.index}].dctm_formats.format[${loopStatusFormats.index}] ,
    wants to bind 'format[${loopStatusFormats.index}]' elements, but this does not happen, although the parent object 'Dctm_formats' has a setter method:

    public void setFormat(
    final int index,
    final java.lang.String vFormat) {
    this._formatList.set(index, vFormat);
    }


    and ${status.value} displays the correct value on my jsp page, but when changing this value and submitting the jsp, I do not get the new value in 'docshifterReceiverConfig' object.


    complete code:

    <c:forEach items="${docshifterReceiverConfig.configuration.re positories.repository}" var="repos" varStatus="loopStatusRepo">

    <spring:bind path="docshifterReceiverConfig.configuration.repos itories.repository[${loopStatusRepo.index}].docbase_name">
    <td width="40%">
    <input name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>">
    </td>

    </spring:bind>


    <c:forEach items="${docshifterReceiverConfig.configuration.re positories.repository[loopStatusRepo.index].dctm_formats.format}" var="formats" varStatus="loopStatusFormats">
    <spring:bind path="docshifterReceiverConfig.configuration.repos itories.repository[${loopStatusRepo.index}].dctm_formats.format[${loopStatusFormats.index}]">
    <tr>
    <td width="40%">
    <input type="text" name="<c:out value="${status.expression}"/>" value="<c:out value="${status.value}"/>">

    </td>

    </tr>
    </spring:bind>
    </c:forEach>

    </c:forEach>


    could anyone help me out on this issue, many thx

  10. #20
    Join Date
    May 2008
    Posts
    12

    Default

    I have the same situation. I want to know, How you collect those selected objects by checked check boxes into controller?
    Last edited by beginner; Jun 9th, 2008 at 11:51 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
  •