How to use STRUTS2 label Select __struts2 Label

Source: Internet
Author: User
example of the implementation of a select form 0x00 HTML code implementation Select form

First, let's take a look at how to implement the simplest select form using pure HTML code, as in the following code:

<select name= "Selectname" >
    <option value= "Chelsea" > Chelsea </option>
    <option value= "Mu" > Manchester United </option>
    ...
</select>


0x01 Struts2 Tag implements select Menu

When we implement a simple select form using the struts tag, how do we do that, the code is as follows:

<s:set var= "teamlist" value= "#{' Chelsea ': ' Chelsea ', ' mu ': ' Manchester United '} ' ></s:set> <s:select name= '"
list= " Teamlist "headerkey=" "headervalue=" Choose your favorite team ></s:select>


0x02 Use the list passed in action to generate a select menu

The Select form implemented by the above example is done using static data, but we need to use Dynamic Data to perform the display of the select form in our work, how to implement the code as follows:

Action Code:

public void Teamaction () {
    private list<team> teamlist;//The List to be displayed on the page//

    here omit the Teamlist getter method

    // The setter method for Teamlist is omitted here
}

Page code:

<s:select list= "Teamlist"  <!--the list-->
      listkey= "team_id" <!--to be displayed from the action  Listkey corresponds to the value attribute in option-->
      listvalue= "Team_name"  <!--Listkey is equivalent to the text content of each option-->
      name= " team.team_id "  <!--Select's Name property-->
      value=" Chelsea ">  <!--Select's default option, Equivalent to setting the Selected= "selected"--> in the corresponding option
</s:select>

The code above is a demo that implements the basic code for using dynamic Data to complete a select form, in which only a few basic tag attributes must be used. Let's take a look at the properties of the full select tag.


second, select tag attributes detailed 0x00 Common Properties list: Create an iterative data source for a list, required items (the list must have a value, and if there is no value, you must set Headerkey, Headervalue). If the list is a map (key, value), then the primary key of the map will be the "value" property of the option (). The value of the primary key corresponds to the text content of the option. Is the option that must be set, if it is a list or a set, then it can be specified by Listkey and ListValue. Headerkey: Sets the header primary key value for the list. Must not be a null value! "'-1 '" or "" is the correct value, "" is the wrong value. Headervalue: The header option value for the list. Listkey: A property of an element object in a list data source that gets the value of an option, corresponding to value in the Select label. ListValue: The property of the Element object in the table data source that gets the text content of the option, corresponding to option in the Select label. Name: The names of the elements. schedule (all attributes):

name must fill Default Value type Description
Emptyoption False False Boolean Whether to add an empty (–) option after the header option
Headerkey False Object/string Sets the header primary key value for the list. Must not be a null value! "'-1 '" or "" is the correct value, "" is the wrong value.
Headervalue False Object/string Header option value for list
Multiple False Object/string Create a multiple-selection list. If the Value property specifies an array (the correct element type), then multiple options specified in the array are preselected.
Size False Integer The size of the Component list box (number of elements displayed)
List True Object/string Creates an iterative data source for the list. If the list is a map (key, value), then the primary key of the map will be the "value" property of the option (), and the corresponding value of the primary key is the text content of the option.
Listkey False Object/string The property of the element object in the list data source to get the value of the option
ListValue False Object/string The properties of the element object in the list data source that are used to get the text content of the option
Theme False Object/string The theme to be used when outputting elements (theme) (not using the default)
Template False Object/string The template to use when outputting elements (template) (not using the default)
CssClass False Object/string Class attribute when output element
CSSStyle False Object/string CSS style definition when output element (translator: is the style attribute of HTML element)
Title False Object/string to set HTML attributes when outputting elements title
Disabled False Object/string Set HTML properties when outputting elements disabled
Label False Object/string An expression that outputs a label for an element
LabelPosition False Left Object/string Not in favor of use.
LabelPosition False Object/string Define the position of the element label (TOP/LEFT)
Requiredposition False Object/string Defines the location of the output of the required property (left
Name False Object/string The name of the element
Required False False Boolean If set to true, this field will be displayed when the label is output (note: If you use the default template, it will be labeled "*")
TabIndex False Object/string Set HTML properties when outputting elements TabIndex
Value False Object/string The Value property of the preset INPUT element.
OnClick False Object/string Set HTML property onclick when output element
OnDblClick False Object/string Set HTML properties when outputting elements ondblclick
OnMouseDown False Object/string Set HTML properties when outputting elements onmousedown
OnMouseUp False Object/string Set HTML properties when outputting elements onmouseup
onmouseover False Object/string Set HTML properties when outputting elements onmouseover
OnMouseMove False Object/string Set HTML properties when outputting elements onmousemove
onmouseout False Object/string Set HTML properties when outputting elements onmouseout
onfocus False Object/string Set HTML properties when outputting elements onfocus
Onblur False Object/string Set HTML properties when outputting elements onblur
onkeypress False Object/string To set HTML properties when outputting elements
OnKeyDown False Object/string Set HTML properties when outputting elements onkeydown
OnKeyUp False Object/string Set HTML properties when outputting elements onkeyup
Onselect False Object/string Set HTML properties when outputting elements onselect
OnChange False Object/string Set HTML properties when outputting elements onchange
ToolTip False String Sets the ToolTip property of an element (note: ToolTip is a ToolTip for the toolbar)
Tooltipconfig False String Setting the configuration of the ToolTip property
Id False Object/string The ID is used when the element is positioned. For UI and form labels it will be used as an HTML ID attribute

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.