Example analysis of select tag usage for struts2

  • 2021-01-25 07:50:47
  • OfStack

This article illustrates the use of the select tag for struts2. Share with you for your reference. The details are as follows:

There is a small problem in the project. Summarize.

About the use of struts2 select label.

ES11en2 from other tables to traverse data fill into the drop-down menu < s:select > Label display.

Version of struts2 is 2.1.8

< s:select
list=""
name=""
value=""
headerKey=""
headerValue=""
listKey=""
listValue=""
/ >
list can store data of type map, list and set

list attribute: Usually defined in action, it must be a source that can be iterated, such as 1 List, Map, Set, etc. If it is one Map, then the key of map corresponds to the value of the select label, and the value of map corresponds to the option of the select label. If it is an List or an Set, it can be specified by listKey and listValue.

listKey and listValue: listKey corresponds to value in the select label, and listValue corresponds to option in the select label. listKey corresponds to option in the select label

(3)name attribute: that is, the name of select in the form.

The following details explain the meaning of each attribute.

ES86en: The default value is ES87en
headerKey: Default name
list: Source data (list can be obtained from the database in the action method)
ES96en: The location where the selected data is stored (here we are in the property value ES98en of the object ES97en < This object needs to be defined in action > )
listKey: name for drop-down options
listValue: value for drop-down options
value: Default

1. Example 1:

<s:select list="{'aa','bb','cc'}" theme="simple" headerKey="00" headerValue="00"></s:select>

2. Example 2:
<s:select list="#{1:'aa',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 setting 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;
  }
}

In jsp page


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

list="programs" list ="programName" listValue="programName" listValue="programName < option value="xxx" > value < /option > This corresponds to the field programName in bean
listKey = "programid" for < value="xxx", value="bean ", value="bean ", value="bean ", value="bean ", value="bean ", s:select will automatically select the value corresponding to select in bean

I hope this article described to everyone Struts programming help.


Related articles: