This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA
< html: text name=" checkoutForm" property=" shippingAddress"/> td> tr> |
< html: text name=" checkoutForm" property=" shippingCity"/> td> tr> |
< html: text name=" checkoutForm" property=" shippingState"/> td> tr> |
< html: text name=" checkoutForm" property=" shippingPostal"/> td> tr> table> ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 12 HTML Tags (cont.) Acts as a bridge between JSP view and other components. Input forms are important for gathering data. Most of the actions of the HTML taglib involve HTML forms. Error messages, hyperlinking, internationalization. HTML tags must be nested within a form tag. Inform handler which bean to use for initializing ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved displayed values. – 13 Struts Tag Libraries - THE BEAN TAG LIBRARY Tags used for accessing JavaBeans and their properties Examples include (define, message, write) Current Total: $ ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 14 Bean Tags (cont.) Tags for accessing beans and their properties Enhancements to <jsp:useBean> Convenient mechanisms to create new beans based on the value of: – – – Cookies Request Headers Parameters ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 15 Struts Tag Libraries THE LOGIC TAG LIBRARY – – – – Managing conditional generation of output text Looping over object collections for repetitive generation of output text Application flow management. Examples include (empty, lessThan, greaterThan, redirect, iterate) Logic Tag Library Example ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 16 Logic Tags (cont.) Provides presentation logic tags for: Value comparisons – Substring matching – match, notmatch Presentation logic – Include: = != <= >= < > forward, redirect Collections – iterate ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 17 ActionForm Java class that extends the org.apache.struts.action.ActionForm. Captures user data from the Http request. Stores the data temporarily. Acts as a “firewall” between the presentation tier and the application. Provides the ability to validate the user input. ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 18 ActionForm (cont.) Provided by developer Define an ActionForm bean (that is, a Java class extending the ActionForm class) for the input form Extend Struts-provided ActionForm class Define it in servlet-config.xml file – – Contains only property getter and property setter methods for each field - no business logic ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 19 ActionForm (cont.) Example package com.jds.apps.hr.employee.form; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; public class EmployeeInfoForm extends AbstractEmployeeForm { public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); // Last Name: if it's empty, has a special character, or exceeds it's maximum length if( objectIsNull.validate(this.getLastName() ) || stringIsEmpty.validate( this.getLastName() ) ){ errors.add("lastName", new ActionError("field.null","Last Name")); } else if( !stringIsValidD.validate( this.getLastName() ) ){ errors.add("lastName", new ActionError("field.invalid.specialcharacter", "Last Name", allowedCharactersD)); ©2005 Accenture All Rights Reserved. } © Accenture 2005 All Rights Reserved else if( !stringLengthIsValidFifty.validate( this.getLastName() ) ){ 20 ActionServlet What Does ActionServlet Do? Performs the role of Controller – – – – Process user requests Determine what the user is trying to achieve according to the request Pull data from the model (if necessary) to be given to the appropriate view, and Select the proper view to respond to the user ©2005 Accenture All Rights Reserved. Delegates most of this grunt work to Action © Accenture 2005 All Rights Reserved 21 Action Class Focus on control flow Process client request by calling other objects (BusinessLogic beans) inside its execute() method Returns an ActionForward object that identifies where control should be forwarded – – – – JSP Tile definition Velocity template Another Action ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 22 Action Class (cont.) What is Action Class? Java class that does the “work” of your application – – Handle request Perform business logic Can be simple or sophisticated – – Simple action class does handle business logic by itself Sophisticated ones invoke Model components ©2005 Accenture All Rights Reserved. 23 Action class functions as a Facade pattern in this case © Accenture 2005 All Rights Reserved Action Class (cont.) Example package com.jds.apps.hr.employee.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionError; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class EmployeeAddAction extends AbstractAction { public ActionForward execute(ActionMapping actionMapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { EmployeeInfoForm viewForm = (EmployeeInfoForm) form; // Determine action, if edit or view mode ©2005 Accenture All Rights Reserved. UserBean userBean = this.getUserBean(request); String userBean.getUserType(); © Accenture 2005userType All Rights = Reserved 24 ActionMapping An ActionMapping object describes an Action instance to the ActionServlet. It represents the information that uniquely defines an instance of a particular action class. Provides useful information to both the Action.execute() and the ActionForm.validate() methods, enabling a developer to alter its behavior based upon the values describing this particular Action. ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 25 Configuring Applications Struts Configuration File Use configuration elements in developing Struts Application. These "static" configuration elements are: All Rights Reserved. 26 Configuring Applications HRS struts-config.xml file <struts-config> Configuring Applications HRS struts-config.xml file (cont.) 28 Configuring Applications HRS struts-config.xml file (cont.) 29 Configuring Applications HRS struts-config.xml file (cont.) Configuring Applications HRS struts-config.xml file (cont.) 31 Resources http://java.sun.com/webservices/docs/1.0/tutorial/d http://struts.apache.org/userGuide/building_model. http://struts.apache.org/userGuide/building_view.h http://struts.apache.org/userGuide/building_control http://struts.apache.org/userGuide/building_contro http://jakarta.apache.org/struts/ ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 32 Questions & Comments . ©2005 Accenture All Rights Reserved. © Accenture 2005 All Rights Reserved 33 Related DocumentsStrutsJune 2020 26StrutsNovember 2019 49StrutsMay 2020 36StrutsNovember 2019 50StrutsNovember 2019 46StrutsJune 2020 5More Documents from "" |