Results 1 to 3 of 3

Thread: bind problems: list, select

  1. #1
    Join Date
    Aug 2004
    Location
    Devon, UK
    Posts
    132

    Default bind problems: list, select

    Hi,

    I am having difficulty getting spring:bind to work on a list.

    My object graph is a little complicated, but if I can get this to work, I can use it over many pages, so I think it is worth the effort.

    Here are the relevant objects:

    Code:
    public class ProfileInfo extends AbstractInfo {
        List populatedSelects;
    .... including getters/setters...
    }
    Code:
    public class PopulatedSelect {
        private Select select = new Select();
        private AttributeRating attributeRating = new AttributeRating();
    .... including getters/setters...
    Code:
    public class Select {
        private String name;
        private String title;    
        private String category;  
        private List options = new ArrayList();
        private int selected;
    .... including getters/setters...
    Code:
    public class AttributeRating {
        private String userName;
        private String attributeName;
        private int rating = 0;
    .... including getters/setters...
    features.jsp:
    Code:
    <TABLE> 
    <c&#58;forEach items="$&#123;profileInfo.populatedSelects&#125;"  var="populatedSelect" varStatus="varStatus">
      	<TR><td><c&#58;out value="$&#123;populatedSelect.select.title&#125;"/></td>
      	<TD>
      	       <spring&#58;bind path="profileInfo.populatedSelects&#91;$&#123;varStatus.index&#125;&#93;.attributeRating.rating">
      	       <select name="<c&#58;out value="$&#123;populatedSelect.select.name&#125;"/>" size="1"> 
    		  <c&#58;forEach items="$&#123;populatedSelect.select.options&#125;" var="option">
    			<option <c&#58;if test="$&#123;populatedSelect.attributeRating.rating == option.index&#125;">selected</c&#58;if> value="<c&#58;out value="$&#123;option.index&#125;"/>"><c&#58;out value="$&#123;option.value&#125;"/></option>
    		  </c&#58;forEach>			
      		</select>
      	     </spring&#58;bind>
      	</TD>  	
      	</spring&#58;bind>
      	</TR>
      </c&#58;forEach> 
    </TABLE>
    I have had to use a Select object, because I have many pages using a variable number of selects, and I needed to keep all these properties in an XML file. I need the AttributeRating object because later I want to make it so that is a user doesn't like any of the options offered in a select, he can fill in his own value into a textfield - but I have removed this code for now.

    It all works in the display, except that the value selected in the select options doesn't get bound to the field AttributeRating.rating.

    Adding the line:

    Code:
    rating test = <c&#58;out value="$&#123;profileInfo.populatedSelects&#91;varStatus.index&#93;.attributeRating.rating&#125;"/>
    after the spring:bind tag outputs the correct value for attributeRating.rating for each tag.

    I guess I have something wrong in the spring:bind tag - can anyone help?

    Many thanks,

    John Pedersen

  2. #2
    Join Date
    Feb 2005
    Posts
    217

    Default Missing the status in your bind

    Code:
    <spring&#58;bind path="profileInfo.populatedSelects&#91;$&#123;varStatus.index&#125;&#93;.attributeRating.rating">
                <select name="<c&#58;out value="$&#123;populatedSelect.select.name&#125;"/>" size="1">
            <c&#58;forEach items="$&#123;populatedSelect.select.options&#125;" var="option">
             <option <c&#58;if test="$&#123;populatedSelect.attributeRating.rating == option.index&#125;">selected</c&#58;if> value="<c&#58;out value="$&#123;option.index&#125;"/>"><c&#58;out value="$&#123;option.value&#125;"/></option>
            </c&#58;forEach>         
            </select>
              </spring&#58;bind>
    Maybe I've gone bleery eyed but I can't see a ${status} reference in your code. Am I missing it?

    Also you have a 2nd "</spring:bind>" after all of that. Is that supposed to close off one not listed in your code?

    I would also look into upgrading to the "${option.value}" syntax versus the <c:out/> one. Easier on the eyes. Also I would see if writting a custom tag would help you out, especially if you are going to use this code in other pages.

  3. #3
    Join Date
    Aug 2004
    Location
    Devon, UK
    Posts
    132

    Default

    Thanks for the reply - I have just got it working now. You were right - it was just the use of 'status' I was missing. This works fine:

    Code:
    <c&#58;forEach items="$&#123;profileInfo.populatedSelects&#125;"  var="populatedSelect" varStatus="varStatus">
      	<TR><td><c&#58;out value="$&#123;populatedSelect.select.title&#125;"/></td>
      	<TD>
      		<spring&#58;bind path="profileInfo.populatedSelects&#91;$&#123;varStatus.index&#125;&#93;.attributeRating.rating">
      			<select name="<c&#58;out value="$&#123;status.expression&#125;"/>" size="1"> 
      			<c&#58;forEach items="$&#123;populatedSelect.select.options&#125;" var="option">
      				<option <c&#58;if test="$&#123;status.value == option.index&#125;">selected</c&#58;if> value="<c&#58;out value="$&#123;option.index&#125;"/>"><c&#58;out value="$&#123;option.value&#125;"/></option>
    			</c&#58;forEach>			
      			</select>
      	     </spring&#58;bind>
      	</TD>
      	<TD><spring&#58;bind path="profileInfo.populatedSelects&#91;$&#123;varStatus.index&#125;&#93;.attributeRating.customRating">
      	<input name="<c&#58;out value="$&#123;status.expression&#125;"/>" type="text" size="40" maxlength="255" value = "$&#123;status.value&#125;">
      	</spring&#58;bind></TD>
      	
      	</TR>
      </c&#58;forEach>  
      </TABLE>
    This lists my selects, and also some textfields that give users the option of filling in their own values if they don't like the choices offered in the select.

    Many thanks,

    John

Similar Threads

  1. Replies: 37
    Last Post: Aug 10th, 2009, 03:35 PM
  2. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  3. Odd behaviour when injecting TransactionTemplate
    By damon311 in forum Container
    Replies: 3
    Last Post: Jul 23rd, 2005, 11:21 AM
  4. Replies: 0
    Last Post: Jun 6th, 2005, 09:23 AM
  5. Velocity Macro - Select List
    By 2devnull in forum Web
    Replies: 8
    Last Post: Aug 21st, 2004, 09:16 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
  •