Presentation is loading. Please wait.

Presentation is loading. Please wait.

Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 

Similar presentations


Presentation on theme: "Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation "— Presentation transcript:

1 Struts 2 Development

2 Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation  Form Submission  Error Handling  Resource Bundles  JSTL and JSF

3 Roles in Struts Development  Web Developer  Uses Struts custom tags, Java Server pages and sample files to create custom web apps  Uses XML, HTML, CSS, JSP and scripting languages to customize pages  Java Developer  programs in Java to develop Controller classes  develops Java Components (Servlets, JavaBeans, etc.) for multi-application use

4 The Controller  FilterDispatcher  Behaves like an Action factory

5 Control Flow Client Request FilterDispatcher Should an action be invoked? ActionMapper

6 Control Flow ActionProxy struts.xml FilterDispatcher ActionInvocation Look up Action class

7 Control Flow Action execute() ActionInvocation struts.xml Look up Result Code

8 The Action Class  POJO  Can contain an instance of the model as member variable because Action classes are instantiated for each request (thread-safe)  Override the execute() method public String execute()  Returns a simple String that serves as a symbolic name to determine what should happen next

9 Configuring the Action Class  Compile the new Action and put it in Web application’s classpath  Add an element to struts.xml  Several elements can use the same Action class as long as name attribute is different..

10 Struts 2 Views  Composed of JSPs, custom tag libraries, and ActionForm objects  JSPs  Present Data  Gather Data  Targets of Action result

11 JSP Targets  Action-Specific Forward <action.... Welcome.jsp Login.jsp 

12 Struts 2 Custom Tags  Tag Library: 

13 Struts 2 Custom Tags  Struts 2 utilizes FreeMarker to generate the markup for the tags.  FreeMarker can generate any type of markup: HTML, XSLT, WML, etc.

14 Validation  Validation is managed at the object level  Fields in an Action class can be checked through configuration file: -validation.xml

15 Validation Example LoginAction-validation.xml <!DOCTYPE validators PUBLIC “-//OpenSymphony Group//Xwork Validator 1.0.2//EN” http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtdhttp://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd>

16 Struts 2 Form Submission  Form state/data combined with Action class

17 Struts 2 Error Handling  Establish ActionError tag on view  Use addActionError to accumulate message on ValueStack addActionError(getText(“error.login”));

18 Defining Resource Bundles  ResourceBundle is a file which contains a series of name/value pairs  Naming format is ResourceBundleName.properties  For example a file named ApplicationResources.properties might contain the entry error.age.invalid=Invalid Age

19 Deploying ResourceBundles  Place a copy of the resource bundles in the /WEB- INF/classes directory of your web application using appropriate package directory structure  Place the following entry in struts.xml

20 Retrieving Localized Messages  Web Page: key attribute  Java: getText() getText(“promptTitle”);

21 JSP Standard Tag Library (JSTL)  Establish a common set of custom tags  Create syntax that eliminates scripting within Web pages  Supports  Core operations (iteration, conditionals)  XML Processing  Internationalization formatting  Database access  The Jakarta Taglibs Standard 1.0 tag library is an implementation of JSTL 1.0.

22 JavaServer Faces (JSF)  Component model for building user interfaces for Web Applications  APIs for managing UI state, handling events and input validation, page navigation  JSP Custom tag library  Benefits  Ease-of-Use  Standardization  Device Independence

23 Review  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation  Form Submission  Error Handling  Resource Bundles  JSTL and JSF


Download ppt "Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation "

Similar presentations


Ads by Google