Example Analysis of struts2 select tag usage and struts2 instance analysis

Source: Internet
Author: User

Example Analysis of struts2 select tag usage and struts2 instance analysis

This example describes how to use the select tag of struts2. Share it with you for your reference. The details are as follows:

Summary.

Use of the struts2 select label.

In struts2, traverse data from other tables and enter the drop-down menu. Use the <s: select> label to display the data.

Struts2 version 2.1.8

<S: select
List = ""
Name = ""
Value = ""
HeaderKey = ""
HeaderValue = ""
ListKey = ""
ListValue = ""
/>
(1) list is a required attribute list that stores map list set data.

List attribute: it is usually defined in action and must be a source that can be iterated, such as a List, Map, Set, etc. If it is a Map, the map key corresponds to the value in the select tag, and the value in the map corresponds to the option in the select tag. If it is a List or a Set, it can be specified through listKey and listValue.

(2) If the list is empty, headKey and headValue cannot be empty. listKey and listValue: listKey correspond to the value in the select tag, and listValue corresponds to the option in the select tag.

(3) name attribute: select name in the form.

The following describes the meaning of each attribute.

HeaderValue: Default value
HeaderKey: default name
List: source data (list can be obtained from the database in the action Method)
Name: location where the selected data is stored (here We <need to define this object in action> In the userName attribute value of object obj)
ListKey: name of the drop-down option
ListValue: the value of the drop-down list.
Value: Default value

1. Example 1:
Copy codeThe Code is as follows: <s: select list = "{'AA', 'bb ', 'cc'} "theme =" simple "headerKey =" 00 "headerValue =" 00 "> </s: select>
2. Example 2:
Copy codeThe Code is as follows: <s: select list = "# {1: 'A', 2: 'bb', 3: 'cc'} "label =" abc "listKey =" key "listValue =" value "headerKey =" 0 "headerValue =" aabb ">
3. Example 3:

<%java.util.HashMap map = new java.util.LinkedHashMap();map.put(1,"aaa");map.put(2,"bbb");map.put(3,"ccc");request.setAttribute("map",map);request.setAttribute("aa","2");%><s:select list="#request.map" label="abc" listKey="key" listValue="value" value="#request.aa" headerKey="0" headerValue="aabb"></s:select>

HeaderKey headerValue is the default value.
4. Example 4

public class Program implements Serializable {  /**  serialVersionUID */  private static final long serialVersionUID = 1L;  private int programid;  private String programName;  public int getProgramid() {    return programid;  }  public void setProgramid(int programid) {    this.programid = programid;  }    public String getProgramName() {    return programName;  }  public void setProgramName(String programName) {    this.programName = programName;  }} xxxextends extends ActionSupport {  private List<Program> programs ;    public List<Program> getPrograms() {    return programs;  }  public void setPrograms(List<Program> programs) {      this.programs = programs;  }}

On the jsp page

<s:select list="programs" listValue="programName" listKey="programid" name="program" id="program"headerKey="0l" headerValue="" value="bean.programid "></s:select> 

Where: list = "programs" is the list in the action, listValue = "programName" is the <option value = "xxx"> value </option> Field programName in the bean
ListKey = "programid" is <option value = "xxx", corresponding to the field programid, value = "bean. programid "is used to set the selected select value. s: select automatically selects the value of the key in the bean.

I hope this article will help you with Struts program design.

Related Article

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.