Struts2 How to set default checked items

Source: Internet
Author: User
The following properties are commonly used in the STRUTS2 select tag:
(1) in the Select tag in Struts2, only one of the properties that must be set is a list.
(2) The list in the select tag must have a value, or it will be an error. If there is no value, you can add Headerkey, Headervalue, so you can pass. Even if there is a value in the list, we usually add Headerkey, Headervalue, which is the first option shown in the list. Note that Headerkey cannot be empty and cannot be-1.
(3) List property: typically defined in action, it must be a source that can be iterated, such as a list, Map, set, and so on. If it is a map, then the map key corresponds to the value in Value,map in the select tag corresponding to option in the select tag. And if it is a list or a set, it can be specified by Listkey and ListValue.
(4) Listkey and Listvalue:listkey correspond to value in the Select tag, listvalue that corresponds to option in the select tag.
(5) Name property: That is, the name of the select in the form.
If you can write dead on the JSP page, you can: <s:select list= "#{1: ' Male ', 2: ' Female '}" listkey= "key" listvalue= "value" value= "2"/>
The code runs the result: "Female" is displayed by default.
If the default entry is uploaded from the background to the foreground, you can: JSP:
<s:select list= "#{' 1 ': ' Male ', ' 2 ': ' Female '}" name= "Sex"/>
Action
Private String sex;
The sex attribute has a get/set method.
Set the sex = "2" in the Business method, and select will be selected by default.

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.