Select/doubleselect label data display in Struts 2

Source: Internet
Author: User

Recently do graduation design used to Struts2 tag library, encountered some more complex data display, the individual or more like to use tag display, Struts2 tags content is rich, but the documentation provided is not very detailed (personally think) under the showcase examples such as: <s: The Select/><s:doubleselect/><s:updownselect/><s:optiontransferselect/> Are some simple value displays, In the actual development is not so simple, if we want to iterate to show the list, Map, set values, what do we do?

Look at the examples in HTML,

  <select name="sex">
  <option value="man">男 </option>
  <option value="women">女</option>
   </select>

Sex indicates that the submitted name,man/women is the value represented by the corresponding page display, and that the male/female is the final value for the page.

And what do we do if we want to display the data in a list collection?

Look at the following JSP page:

  <select name="department">
  <%
   Department department = null;
   List list = (List) request.getAttribute("list");
   Iterator iter = list.iterator();
   while (iter.hasNext()) {
   department = (Department) iter.next();
  %>
  <option value="<%=department.getDep_name() % >"><%=department.getDep_name()% >&nbsp;&nbsp;&nbsp;</option>
  <%
  }
  %>
   </select>

The iteration is Department's property Dep_name, which appears cumbersome, if the iterator output might be better, with JSTL output:

  <c:forEach var="department" items="" varStatus="status">
   <tr>
   <td>${status.dep_name }</td>
   <td>${status.dep_id }</td>
   <td>......</td>
   </tr>
  </c:forEach>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.