Struts2 UI tag

Source: Internet
Author: User

Struts2 UI tag
All UI tags of themes and templates are based on themes and templates. One template is a file written using JSP, velocity, or freemarker to generate HTML, some templates with a shared view are organized together to form a topic. Struts2 uses the directory name as the primary title. template files with a common view are stored in the same directory.
As a UI tag on a JSP page, you can set the template required for the UI tag or the topic used by the UI tag. It is not recommended to set template attributes directly, but select a specific topic.

Topic setting method: the priority is also in the following order
1. Specify a topic by setting the tehme attribute on a specific UI tag
2. Specify the topic by setting the theme attribute of the form tag on the periphery of a specific UI tag.
3. The topic is determined by Attributes named theme in the drive page session range.
4. Obtain the theme attribute in the request range to determine the topic.
5. Obtain the theme attribute in the session range to determine the topic.
6. Obtain the attributes named theme in the application scope to determine the topic.
7. Obtain a constant named struts. UI. Theme (the default value is XHTML) to determine the topic. The variable can be determined in the Struts. properties file or the Struts. xml file.

Built-in topic:
Simple (default topic), XHTML, css_xhtml, Ajax
XHTML and css_xhtml themes are both packaged and extended for simple themes.
Simple topic. Each UI tag generates only one simple HTML element and no additional content.

The XHTML topic and the default topic of strutss. Simple is extended. The following additional features are added to the basics of this topic:
1. Use standard two-column table layout for HTML tags
2. The label of each HTML tag can be displayed on the left or top of the HTML element, depending on the lableposition attribute settings.
3. Automatically output validation error messages
4. Output JavaScript client Verification

Css_html adds CSS style control to the XHTML topic

Ajax provides additional Ajax support for each tag on the XHTML subject. Ajax support is based on dojo and DWR
Added the following features:
1. Added client verification in Ajax Mode
2. support asynchronous submission of remote forms (preferably with the submit tag)
3. Provides advanced Div tags to allow partial HTML update.
4. Provides advanced a labels that allow dynamic loading and execution of remote JavaScript code
5. Provides tabbedpanel supporting Ajax
6. Provides the pub-sub event model of the rich client model.

DividedForm tagAndNon-form tag

Form label from label and the label of a form Element
Form textfield passwordradio
Checkboxlist select doubleselect ComboBox optiontrasferselect
Optgroup updownselect textera
Reset submit token headlabel

All common attributes inherit the uibean class.
① Attributes related to the template. You can specify the template and topic used by the form tag.
Templatedirstring specifies the template directory
Themestring specifies the topic name
Templatestring specifies the Template Name

② JavaScript-related attributes. The topic is simple.
Onkeyup (release) onkeydown (Press) onkeypress (click a character key on the form)
Ondblckick (double-click a form element)

③ Tool-related attributes
Tooltipstring: tooltip for setting this component

④ Common attributes of form labels
Cssclass cssstyletitledisabled
Label (lable associated with form elements) labelposition (label position)
Requiredposition (required) name (corresponding to form name ing and action)
Required (whether to add + to the lable of the form element)
Tableindexvaluekey (set the attribute name of the action corresponding to the form element)

⑤ All form Element labels have a special form attribute.
Purpose: reference the form in which the form element is located. Through this form attribute, the interaction between the form element and the form can be realized.
Use $ {parameters. Form. ID} to obtain the ID of the form where the form element is located.

Detailed description of the name value attribute:
The Name property is mapped to the property name in the action, and the value property represents the value of this property.
Recommendation 1: struts2 has automatically processed the assignment of attribute content
① Bind the value of the text box below to the firstname of the person attribute of the action.
<S: textfield name = "person. firstname"/>
② Generate the values of form elements using expressions
<S: textfield name = "person. firstname" value = "$ {pserson. firstname}"/>

A large number of form tags are provided. Most form tags correspond one to one with HTML form elements.

Common and special form tags:

① Form Tag: outputs an HTML form
Action: Specifies the submitted action. Do not add a. Action suffix
Namespace Method
Enctype is set to multipart/form-data when uploading files
Foucuselement specifies the ID of an element. The page loads the element with focus.
Whether to perform client verification for validate. Valid only when XHTML or Ajax is used.

② The submit tag is used to output a submit button.
Type [input image button] SRC [Image address of the image type]
Action [specify the action to process the request] method [specify the action method to process the request]

③ Textfield label, a single line text box
Maxlength [Maximum length of input characters] readonly [Read-Only] size [visible size]

④ Password tag, output a password input box
Maxlength [Maximum length of input characters] readonly [Read-Only] size [visible size] showpassword [show Password]

⑤ Textarea, output a multi-line text box
Cols [column] rows [row] readonly [Read-Only] Wrap [whether to wrap]

⑥ Select: to output a drop-down list box, you must specify the list attribute to specify the set [object instances in the map set of a Common set]
List [if the set of iterations is map, the key becomes the value of the Option map and the value becomes the option content]
Multiple [whether to select multiple options]
Size [number of displayed options]
Listkey [specify the attribute in the set as the value of the Option]
Listvalue [specify the attribute in the object in the set as the option content]
Headerkey [If header is selected, the submitted value cannot be set to null if this attribute is used]
Headervalue [content displayed in Header Options]
Emptyoption [whether to add an empty option after the header]

Common form tag usage

<S: Form>
<S: textfield name = "username" label = "username:">
<S: password name = "password" label = "Password:">
<S: textarea name = "personal" Cols = "30" rows = "5" label = "Profile:">
<S: Select name = "education" label = "highest degree"
List = "# {1: 'High school', 2: ''}"/>
<S: Submit value = "Submit">
<S: Form>

Special labels

① Checkbox checkboxlist [multiple choice] multiple check boxes can be created at a time. To generate multiple check boxhtml tags, you must specify the list
List required
Specifies the set of iterations. If map is used, the key becomes the value and the value is the content.
Listkey specifies the property of the collection object as the property key.
Listvalue specifies the attribute of the Set object as the option content.

② ComboBox generates a combination of a single row text box and a drop-down list box, but the two form elements correspond to only one request parameter. Only the values in the single row text box contain the request parameter, while the drop-down list box is only used for auxiliary input.
List required
Generate various options
Maximum length of characters entered in the maxlength large row text box
Readonly size
Visual size and read-only

③ Doubleselect is useful
Generate a cascade list. Set options for two list boxes
List listkey
Listvalue headerkeyheadervalue
Doubleid doublelistdoublelistkey

④ Head is used to claim HTML head is used to claim reference to CSS and JS
Use theme = "ajax" to indicate that the Ajax header information is included in the page.

⑤ Token prevents multiple submissions from refreshing pages and submitting multiple times
Enable tokeninteceptor or tokensessionstoreinterceptor interceptor in the struts2 configuration file
The principle is to add a hidden field to a form. The value of each field added to a page is different. The interceptor intercepts hidden domain values. If the values are the same twice, the organizational form is submitted.
<S: From> <s: token/> </S: From>

Special form tag usage
<S: Head/>
<S: form name = "test">
<S: checkboxlist name = "interest"
List = "{'1', '2', '3', '4 '}"
Label = "interest"/>
<S: ComboBox label = "information channel" name = "channel"
List = "{'1', '2', '3'}" headerkey = "-1"
Headervalue = "select"
Emptyoption = "true"/>
<S: doubleselect
Lable = "Province" name = "Province" list = "{'1', '2', '3'}" doublelist = "Top
= '1 '? {'1', '2', '3 '}
: Top ='
2 '? {'1', '2', '3 '}:
Top = '3
'? {'1', '2', '3 '}
</S: Form>

Non-form tag

A href [generate URL address]
Actionerror actionmessage output information. The former outputs the getactionerror method return value of the action instance.
The latter outputs the returned value of the getactionmessage () method.
Addactionerror addactionmessage in Actino

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: 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.