Struts2 -- form tag, struts2 -- form

Source: Internet
Author: User

Struts2 -- form tag, struts2 -- form

Form labels of struts2 can be divided into two types: form labels themselves and other labels that wrap HTML form elements. The behavior of the form tag is different from that of its internal elements.

Struts2 form labels include:

Form, textfield, password, radio, checkbox, checkboxlist, select, doubleselect, combobox, optiontransferselect, optgroup, updownselect, textaarea, hidden, file, label, submit, token, head

Checkbox outputs a check box

Checkboxlist outputs a check box list

Combobox outputs a widget that can be filled with a text box from the content of the drop-down box.

Datepicker output a date selection missing, using javaScript and DOM

Doubleselect outputs a two-choice drop-down box component. The second drop-down box depends on the first one.

Head outputs the content of the head part corresponding to theme, such as css and javaScript references.

File output a file selection box

Form

Hidden outputs a hidden form field

Label

Optionstransferselect outputs an option move drop-down component, mainly used for two drop-down boxes and the buttons used to move options between two drop-down boxes

Password: Output a password input box.

Radio outputs a single worker

Reset outputs a reset form button

Richtexteditor outputs a Rich Text Editor

Select to output a drop-down box

Submit outputs a text input box

Token outputs a hidden field to prevent multiple forms from being submitted.

Updownselect outputs a drop-down box component with up and down buttons to move the drop-down box component element.

 

The name attribute and value Attribute of this multi-form tag (except form tag) have a unique relationship. In addition to specifying a name for an html form element, the name attribute is also mapped to the Action attribute when the form is submitted as the name of the request parameter.

In most cases, the name attribute is mapped to a simple JavaBean attribute. For example, if the value of the name attribute is "postalCode", after the form is submitted, the struts2 framework will call the setPostalCode () of the Action () to set properties.

Sometimes you want to display the data of the Action attribute in the form element. In this case, it is the turn of the value attribute to specify the expression % {postalCode} For the value attribute. The getPostalCode () method of the Action will be called, the returned data is displayed in the form. After that, you can edit the value and submit it.

1. form tag

The form tag outputs an html input form. In addition, the form tag of the xhtml topic outputs the table outside the form element.

  • Normally, the request for the output form of the retaining wall and the request for submitting the form belong to the same namespace. For example: Request/admin/updateCategory! The form output by default. action. The namespace is assumed to be/admin. Therefore, the namespace attribute can be used when the form label is used. For example, <s: form action = "updateCategory"> If the output form request and the submitted form request score are different from the namespace, you can use the namespace attribute to specify the namespace of the action to process the form.
  • If a form is output using a non-execute method of the action and then submitted to the default execute method of the action, the action attribute of the form tag can be fooled. For example: <s: form> <s: textfeld name = "username" label = "username"/> <s: submit/> </s: form> when accessing/register! When default. action is used, the form is output. The form tag automatically sets the Action attribute to register, so that the execute method of action is executed after the form is submitted.
  • Methoe and enctype are attributes of html form labels.
  • When the verification framework is used, set the form tag's validate attribute to true, and the client's JavaScript verification code is automatically generated. <S: form action = "register" method = "post"/>

The default topic of struts2 is xhtml. The above code is output in the client browser as follows:

<S: form id = "register" onsubmit = "return true" action = "register" method = "post">

<Table class = "wwForm Table"> </table>

</S: form>

You can see that a table element is output in the form label.

2. textfield tag

The textfield tag Outputs An HMTL single-line text input control, which is equivalent to: <input type = "text".../>

<S: form action = "register" method = "post">

<S: textfield name = "username" lable = "username"/>

</S: form>

3. password tag

The password tag outputs an HTML password input control, which is equivalent to: <input type = "password".../>

4. textarea tag

The textarea tag outputs an html multi-line text input control, which is equivalent to: <textarea...> </textarea>



5. select tag

The select tag outputs an html list box, which is equivalent to: <select...> <option...> </option> </select>







6. optgroup labels

The optgroup label is used as the word label of the select label to create the limit group. You can use one or more optgroup labels in the label body of the select tag to perform a logical analysis group on the options. Note that optgroup labels cannot be nested.



7. radio labels

The radio tag outputs a set of hmtl radio buttons, which are equivalent to: <input type = "radio".../>

8. checkbox tag

The checkbox label outputs an html check box, which is equivalent to: <input type = "checkbox".../>

9. checkboxlist tag

The checkboxlist tag uses a list to create a series of check boxes. The attribute settings are similar to those of <s: select/> and <s: radio/>, but the html check box is created. The difference is that the checkboxlist label is a multiple-choice label.

<S: form>

<S: checkboxlist name = "interest" list = "{'soccer ', 'basketball', 'volleyball ', 'swimming'}"/>

</S: form>

10. hidden tag

The hidden tag outputs an html hidden form element, which is equivalent to: <input type = "hidden".../>

<S: hidden name = "id" value = "5"/>

11. submit tag

The submit tag outputs a submit button. The submit tag and form tag can be used together to provide the asynchronous form submission function. The submit tag can output the following three types of submit buttons.

Input: equivalent to: <input type = "submit".../>

Image: equivalent to: <input type = "image".../>

Button: equivalent to: <input type = "button".../>

12,

  • Action prefix
  • Redirect prefix
  • Redirect-action prefix
  • Method prefix

13. reset tags

14. label

15. token tag and file tag

16. Non-form tags






 

 

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.