Usage of <s: checkboxlist/> In struts2

Source: Internet
Author: User

HTML code

  1. Select a role <br>
  2. <S: checkboxlist list = "# request. roleuserlist "listkey =" roleid "listvalue =" rolename "value =" # request. rolelist. {roleid} "name =" roleids "> </S: checkboxlist>

 

Note:

Where # request. roleuserlist corresponds to the list of roleuserlist in the request scope in the background;

Listkey = "roleid"

The roleid corresponds to the roleid of the bean in the background roleuserlist, And the listkey is also the value to be passed in to the background;

Listvalue = "rolename" is naturally the content displayed on the page;

Value = "# request. rolelist. {roleid }"

Select the default value for S: checkboxlist and put the corresponding background in the request scope.RolelistRoleid in this list is combined into an array,

Similar to {1, 2, 3}, then the tag will automatically match.

Name = "roleids" This roleids can be set in the background action by using the Get Set roleids array attribute or directly using the request scope value, which must be placed in the array;

 

 

 

Struts2 S: checkboxlist

 

A new ut tag s: checkboxlist is added to struts2. The following describes how to use it.
S: checkboxlist is used to display a set of check boxes on the screen. The default value is horizontal output. Next we will introduce how to modify the FTL file so that it can be output in any way.
Label format:
<S: checkboxlist name = "" list = "" listkey = "" listvalue = "" value = ""/>
Name-defines the tag name, which is used to receive the check boxes selected on the screen. Therefore, it should be consistent with the attributes defined in the action and are mostly arrays;
List-defines the set variables used to output the check boxes to the screen. Generally, a list or map attribute is defined in the action;
Listkey-if a list is defined in the action, a bean is often defined in the list. It has only two attributes, one of which (such as ID) is set here;
If a map is defined in action, the map key is set here;
Listvalue-if a list is defined in the action, a bean is often defined in the list. It has only two attributes, and the other (such as name) is set here;
If a map is defined in action, the MAP value is set here;
Value-used for the check box selected on the echo screen. If there is an input check on the screen, if there is an error, the original screen is returned and an error message is displayed. In this case, you need to use it.
Generally, you can set it to be consistent with the name.
Note:
To correctly display the selected check boxes, make sure that the array type of name is consistent with that of listkey.
For example, if name is set to string [] users, the listkey is set to string ID. If name is set to integer [] users, the listkey is set to integer ID;
Modify the FTL file to change the output mode:
1. Search the struts2-core-xxx.jar, find the checkboxlist. FTL file, copy it out;
2. Create a template. Simple package under SRC of your project and place the above files;
3. open the file in a text editor, modify it to the desired output format, and save it. OK;

 

 

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.