Struts2 's Modeldriven understanding

Source: Internet
Author: User

inuseractionas an example, whenuseractionrealized theModeldriveninterface, the default configured interceptor associated with the interface determines that the request is going to beuseractionProcessing anduseractionrealized theModeldriveninterface, so you can perform auseractionbefore calling the corresponding method of theGetmodelmethod that willuseractionin theModelclasses (such as Use)Robject (assuming that theu) Press-inValuestackin, asRootobject. At this time, if the submitted form orURLvalue, for example .username,Passwordand so on, will be directly assigned touTo store properties in an object, avoiding theControllerWrite a large number of attributes andGetsetmethod, but also avoids writing a large number ofu.xxxx,u.xxxresulting in comprehension difficulties and not intuitive).

InS:Debugdisplayed on the page, you can see that at this time aUserclass at the top of the stack, the property isusernameand thePassword(its value can be submitted through the form andURLPass), below the top of the stack isuseractionclass, property isuand theModeltwo pairsUserobject that points to the root of the stack at the top of theUserObject-----①.

However, ifuseractionthe corresponding--The method of the request is Getmodel after theupoint to a differentUserObject(useractionin theModelProperties, andualso points to the new object, which can be understood as if the subsequent executionGetmodelmethod, then thisModelthe object that is pointing to will be pressed into), then this object will not be pressed intoValuestack, not asRootobject, so its properties are not treated asRootobject properties, not added#the direct fetch toViewerthe page.

At this point, in the View page, take u.username, but can take the value of the new object, can fetch the value is not difficult to understand, but why you are not now root , not in front of the # can be taken? The reason is that u.username in the top of the stack can not find, will be found in the next, found after the return.

Assuming that after the Getmodel method is called , the useraction method does not assign u to a new object, but instead uses the How about the U.setusername method? So, because of the reason of ①, when you point to the root object, you can change the root the value of the username. To achieve the purpose of the update.

In the source code of Modeldriveninterceptor, you can see that there is a Refreshmodelbeforeresult property of false, and if set to true, the Getmodel is called once after the Useraction method call. If the direction of U changes at this point, the object that you are pointing to will be pushed into the stack to achieve the purpose of updating.

Modeldriven understanding of Struts2

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: 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.