Struts2 specifies the generic type of the Set element and the struts2 set element.

Source: Internet
Author: User

Struts2 specifies the generic type of the Set element and the struts2 set element.

Public class LoginAction implements Action {

Private List users;
Public void setUsers (List users ){
This. users = users;
}
Public List getUsers (){
Return this. users;
}
Public String execute () throws Exception {
Return "SUCCESS ";
}
}

 

For example, if we do not use generics, struts2 cannot know the type of the Set element in the users attribute of Action.

Struts2 allows developers to specify the type of the collection element through local type conversion files. The type conversion file is a common Properties (. * properties) file. The type conversion file provides the type conversion configuration information.

The file name of the type conversion file should be in the form of a ActionName-conversion.properties, where ActionName is the class name of the Action, followed by the-conversion. properties string is a fixed part. The type conversion file should be placed in the same location as the Action file.

For example, to provide a type conversion file for the preceding Action, create a new LoginAction-conversion.properties file under the same directory of the Action, and then add the key-value pair to the file

Element_users = com. test. domain. User

The Set element type of the users set attribute is com. test. domain. User.

For Map-type attributes, both the key type and value type of Map must be specified. To specify the key type of the Map type attribute, add the following items to the type conversion file:

Key _ <MapPropName >=< KeyType>

The Key is a fixed syntax, <MapPropName> is the attribute name of the Map type attribute, and the composite type specifies the fully qualified class name of the Map Key value.

To specify the value type of the Map attribute, add the following items to the local type conversion file:

Element _ <MapPropName >=< ValueType>

Element is a fixed syntax, and <MapPropName> is the attribute name of the Map type attribute. The composite type specifies the value of the Map attribute and deserves a fully qualified class name.

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.