150 likes | 542 Views
Struts2.0. Revolution to next generation. Basic features of struts2.0. Struts2 vs struts1.1. Architecture of struts2.0. Basic flow of struts2.0. How to configure the plugins for struts2 in netbeans IDE. Some basic components in brief. Reference. Topics discussed …. Features.
E N D
Struts2.0 Revolution to next generation Avishek Arang :: avishekarang@gmail.com
Basic features of struts2.0. • Struts2 vs struts1.1. • Architecture of struts2.0. • Basic flow of struts2.0. • How to configure the plugins for struts2 in netbeans IDE. • Some basic components in brief. • Reference Topics discussed … Avishek Arang :: avishekarang@gmail.com
Features Page-based Navigation Built-in Ajax Support: DWR and Dojo Spring as default inversion of control container Changed from front-controller servlet to filter Much better client-side validation support QuickStart and Annotations JSF Support Built-in support for testing with StrutsTestCase Avishek Arang :: avishekarang@gmail.com
Comparison Struts2.0 Struts1.1 • Action • Action or POJO • Result • struts.xml • FilterDispatcher • Interceptors • Action-validation.xml • Action • ActionForm • ActionForward • struts-config.xml • ActionServlet • RequestProcessor • validation.xml Avishek Arang :: avishekarang@gmail.com
Architecture Avishek Arang :: avishekarang@gmail.com
Flow of Struts 2 based Application User Sends request. FilterDispatcher determines the appropriate action. Interceptors are applied. Execution of Action. Output rendering. Return of Request(reverse order). Display the result to user. Avishek Arang :: avishekarang@gmail.com
Select Tools > Plugins: To configure struts plugins to netbeans IDE. Avishek Arang :: avishekarang@gmail.com
Configure Plugins: org-netbeans-modules-web-frameworks-struts2.nbm org-netbeans-modules-web-frameworks-struts2lib20011.nbm Avishek Arang :: avishekarang@gmail.com
Struts 2 Core components Struts 2 Core components are Action handler, Result Handler and Custom Tags. Action handlerAction handler interacts with other layers. Result HandlerResult handler actually dispatches the request to view. Custom Tags Custom Tags are used render the dynamic content. InterceptorsThe Interceptors are used to specify the "request-processing lifecycle" for an action. Interceptors are configured to apply the common functionalities like workflow, validation etc.. to the request. Interceptors code is executed before and after an Action is invoked Expression Language(ONGL- Object Graph Notation Language) Avishek Arang :: avishekarang@gmail.com
struts.xml <struts> <include file="struts-default.xml"/> <constant name="struts.custom.i18n.resources" value="MessageResources" /> <package name="default" extends="struts-default"> <action name="list" class="web.DefectsList"> <result>/pages/defects.jsp</result> </action> <action name="action_*" method="{1}" class="web.DefectsAction"> <result name="input">/pages/editDefect.jsp</result> <result type="redirect">list.action</result> </action> </package> </struts> Avishek Arang :: avishekarang@gmail.com
<include> Used to modularize application. Always a child of <struts> tag. Only attribute “file” implies the config file. <include file=“module1-config.xml”> Order of including files are important. explicitly include: “struts-default.xml” and the “struts-plugin.xml” files Avishek Arang :: avishekarang@gmail.com
<package> name - unique. extends - “struts-default”. namespace- admin, knowledgecenter, test. Abstract-if “true” actions configured will not be accessible via the package name. Avishek Arang :: avishekarang@gmail.com
Interceptor They provide a way to supply pre-processing and post-processing around the action. examples include exception handling, file uploading, lifecycle callbacks and validation. <interceptors> <interceptor name="autowiring“ class="interceptor.ActionAutowiringInterceptor"/> </interceptors> <action name="my" class="com.fdar.infoq.MyAction" > <result>view.jsp</result> <interceptor-ref name="autowiring"/> </action> Avishek Arang :: avishekarang@gmail.com
com.opensymphony.xwork2 Interface Action Field Summary static StringERROR The action execution was a failure. static StringINPUT The action execution require more input in order to succeed. static StringLOGIN The action could not execute, since the user most was not logged in. static StringNONE The action execution was successful but do not show a view. static StringSUCCESS The action execution was successful. Method Summary Stringexecute() Where the logic of the action is executed. Avishek Arang :: avishekarang@gmail.com
Bibliography - www.roseindia.com- Starting Struts2 by Ian Roughley [free ebook].- Struts 2 Design and Programming: A Tutorial by Budi Kurniawan. Avishek Arang :: avishekarang@gmail.com