Announcement Announcement Module
Collapse
No announcement yet.
select form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • select form

    Is this how one does an html SELECT list with spring? It's ugly but it works. (I'm hoping someone has something better.)
    Code:
    <spring&#58;bind path="sifd.facility">
    <select name="facility">
    <option value="dwmf"
    <c&#58;if test="$&#123;status.value=='dwmf'&#125;">
    selected="true"
    </c&#58;if>
    >&#40;DwMF&#41; Dwinelle Microcomputer Facility</option>
    <option value="emf"
    <c&#58;if test="$&#123;status.value=='emf'&#125;">
    selected="true"
    </c&#58;if>
    >&#40;EMF&#41; Evans Microcomputer Facility</option>
    <option value="lsmf"
    <c&#58;if test="$&#123;status.value=='lsmf'&#125;">
    selected="true"
    </c&#58;if>
    >&#40;LSMF&#41; Life Sciences Microcomputer Facility</option>
    <option value="mmf"
    <c&#58;if test="$&#123;status.value=='mmf'&#125;">
    selected="true"
    </c&#58;if>
    >&#40;MMF&#41; Moffitt Microcomputer Facility</option>
    <option value="wmf"
    <c&#58;if test="$&#123;status.value=='wmf'&#125;">
    selected="true"
    </c&#58;if>
    >&#40;WMF&#41; Wheeler Microcomputer Facility</option>
    </select>
    </spring&#58;bind>

  • #2
    Hi,

    basically, your approach is alright.

    However, it's better practice to put data like the available elements of the combo box into the model using the Controller's referenceData() method like this:

    Code:
    protected Map referenceData&#40;HttpServletRequest httpServletRequest&#41; throws Exception &#123;
      Map model = new HashMap&#40;&#41;;
      
      Collection facilities = new HashSet&#40;&#41;;
      facilities.add&#40;new Facility&#40;"dwmf", "DwMF&#41; Dwinelle Microcomputer Facility"&#41;&#41;;
      facilities.add&#40;...&#41;
    
      model.put&#40;"facilities", facilities&#41;;
    
      return model;
    &#125;
    Then, you can use this data in your JSP like this:

    Code:
    <spring&#58;bind path="sifd.facility">
    <select name="<c&#58;out value="$&#123;status.expression&#125;"/>" >
    <c&#58;forEach items="$&#123;facilities&#125;" var="facility" varStatus="loopStatus">
      <option value="<c&#58;out value="$&#123;facility.id&#125;" />" <c&#58;if test='$&#123;facility.id == status.value&#125;'> selected </c&#58;if>>
    	<c&#58;out value="$&#123;facility.longDescription&#125;" />
    </option>
    </c&#58;forEach>
    
    </select>
    Hope this helps.

    Kind regards,
    Simon

    Comment


    • #3
      Thanks. I was just thinking about that after I posted it; pulling the list from the database.

      Comment

      Working...
      X