Struts2-Learning Note Series (9)-OGNL type conversion and type binding

Source: Internet
Author: User

Html:

1 <s:form action= "Login" >2     <s:textfield name= "User.Name" label= "username" ></s: Textfield>3     <s:textfield name= "user.pwd" label= "password" ></s:textfield>4     <s:submit value= "Submit" ></s:submit>5 </s:form>67  

Attention:

The action class contains the user instance and has a get and set method. Framework uses set method and reflection to construct user instance

Collection type Binding

9.1. Bind Map

1 <s:form action= "Login" >2     <s:textfield name= "users[' one '].name" label= "User name" > </s:textfield>3     <s:textfield name= "users[' one '].pwd" label= "password" ></s:textfield> 4     <s:textfield name= "users[' two '].name" label= "username" ></s:textfield>5     <s:textfield name= " users['].pwd "label=" password "></s:textfield>6     <s:submit value=" Submit "></s:submit >7 </s:form>

9.2 Binding List

1 <s:form action= "Login" >2     <s:textfield name= "users[0].name" label= "username" ></s: Textfield>3     <s:textfield name= "users[0].pwd" label= "password" ></s:textfield>4     <s:textfield name= "users[1].name" label= "username" ></s:textfield>5     <s:textfield name= "Users[1].pwd" label= "password" ></s:textfield>6     <s:submit value= "Submit" ></s:submit >7 </s:form>

9.3 External mapping files

Defining a List Object

1 PrivateList users;2 3  PublicString Execute ()throwsException {4User user= (user) Getusers (). Get (0);5     if(User.getname (). Equals ("Zcx")){6Addactionmessage ("Conversion succeeded");7         returnSUCCESS;8     }9Addactionmessage ("Conversion failed");Ten     returnERROR; One } A  -  -  PublicList getusers () { the     returnusers; - } -  -  Public voidsetusers (List users) { +      This. Users =users; -}

External files:

Loginaction-conversion.properties

-conversion.properties: Fixed part

Loginaction: For the Action class name

Element_: Fixed part

Users: Member Names

For map type objects, you need to use the

Key_<mappropname>=<valuetype>

<mappropname>:map property names for type properties

Element_users=domain. User

Struts2-Learning Note Series (9)-OGNL type conversion and type binding

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.