Results 1 to 3 of 3

Thread: customize ItemValue in <form:option>

  1. #1
    Join Date
    Mar 2011
    Location
    Belgium
    Posts
    13

    Default customize ItemValue in <form:option>

    Hello,

    I have a select and i'm using <form:options itemValue="" itemLabel=""/> to show the options.

    Is it possible to insert custom values into itemValue ?
    For example <form:options itemValue="FIELD1 ' AND ' FIELD2" itemLabel="FIELDID"/>

    Thanks for your help

  2. #2
    Join Date
    Oct 2005
    Location
    Mobile, AL
    Posts
    345

    Default

    You could do this:

    Code:
    <form:select>
        <c:forEach items="${yourItemCollection}" var="currObj">
            <form:option value="${field1} ${field2}"><c:out value="${FIELDID}"/></form:option>
        </c:forEach>        
    </form:select>
    The question I have is how are you going to bind the value back to your command bean? Are you really wanting to combine two fields for the label or the value?

    One other option is to add a getter method on your command object that does the field combination for you.

  3. #3
    Join Date
    Mar 2011
    Location
    Belgium
    Posts
    13

    Default

    One other option is to add a getter method on your command object that does the field combination for you.
    I don't know why I didn't think about it earlyer...
    I'm using Hibernate, I just had to define a new getter and specify it as Transient..

    Now i'm using this simple code :
    Code:
    <form:options items="${myList}" itemValue="keyField" itemLabel="myFieldCombinationGetter"/>
    However, I don't really like it. If you often use this tip, you'll have an huge bean definition. You're creating a new method for each new display you want in your view.. I guess you should avoid this kind of dependencies..

    Ofcourse, I wanted to combine fields for my label, not my value

    Thanks for your answer
    Last edited by libuma; Apr 6th, 2011 at 01:37 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
  •