Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 1 Struts2 Reinventing Struts1 Wheel Ori Dar Consultant and Architect, AlphaCSP.

Slides:



Advertisements
Similar presentations
Struts 2.0.
Advertisements

Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Apache Struts Technology
A Blackboard Building Block™ Crash Course for Web Developers
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Struts 2 Interceptors By, Srinivas Reddy.S
Spring, Hibernate and Web Services 13 th September 2014.
Web MVC-2: Apache Struts Rimon Mikhaiel
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
© 2005, Cornell University. Rapid Application Development using the Kuali Architecture (Struts, Spring and OJB) A Case Study Bryan Hutchinson
{ Apache - Click By, By, Anupam Mundale. Anupam Mundale. Viraj Kulkarni. Viraj Kulkarni.
Apache Struts Technology A MVC Framework for Java Web Applications.
Session-01. Layers Struts 2 Framework The struts 2 framework is used to develop MVC-based web application. Struts 1.0 was released in June The.
Session-02. Index. Jsp in Struts 2 Web.xml File in Struts 2.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
© Internna Technologies 1 IWebMvc Features, Possibilities & Goals.
Struts 2.0 an Overview ( )
Introduction to Struts 2.0 Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv Software School,Fudan University 1.
Struts. Agenda Preface Struts and its components An example The architecture required for Struts Applications.
UNIT-V The MVC architecture and Struts Framework.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
DSpace XML UI Project Texas A&M University Digital Initiatives, Research and Technology Scott Phillips, Cody Green, Alexey Maslov, Adam Mikeal, Brian Surratt,
WebWork in Action An introduction to WebWork Patrick A. Lightbody.
JavaServer Faces: The Fundamentals Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator; IBM RAD)
11. Java-Based Web: JSP, JSF. 2 Motto: Rule 1: Our client is always right Rule 2: If you think our client is wrong, see Rule 1. - Anonymous.
Java Server Faces Çağatay Çivici Apache MyFaces Team Member
Java Beans.
Spring Overview, Application demo -Midhila Paineni 09/23/2011 Spring Overview, Application demo9/8/20151.
Welcome to Library Management System
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Basic Struts Architecture Client Server Database Request Response Control View Model Server Struts Framework.
Struts2 Plugin Development - Extending Struts2 Justin Yip.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Stanisław Osiński, 2002JSP – A technology for serving dynamic web content Java Server Pages™ A technology for serving dynamic web content Stanisław Osiński,
Introduction to Web Dimitar Nenchev Ivan Nakov
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Forms with Spring MVC Handling Form.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Struts 2 introduction. Struts 2 framework Struts 2 A full-featured web application framework for the Java EE platform The Java Servlet API exposes the.
REVOLUTION TO NEXT GENERATION Struts2.0 20/02/ Avishek Arang ::
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
INTEGRATION OF BACKBONE.JS WITH SPRING 3.1. Agenda New Features and Enhancements in Spring 3.1 What is Backbone.js and why I should use it Spring 3.1.
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Struts 2 Introduction.
Data transfer and type conversion One of the common tasks of the web application domain was moving and converting data from string-based HTTP to the various.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
Apache Struts Technology A MVC Framework for Java Web Applications.
J AVA T RAINING IN A HMEDABAD By TOPS Technologies 1 TOPS Technologies Java Course.
Model View Controller. MVC is the separation of model, view and controller. It's simply a paradigm; an ideal that you should have in the back of your.
Ext JS - Direct Bridging The Gap A DMSBT Presentation By Timothy Chandler.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Best Struts 2 Training By TOPS Technologies.
Getting Started with Alfresco Development
Struts 2 Validation Framework
Unit 6-Chapter 2 Struts.
The Model Layer What is Model?
JavaServer Faces: The Fundamentals
Presentation transcript:

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 1 Struts2 Reinventing Struts1 Wheel Ori Dar Consultant and Architect, AlphaCSP

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 2 Agenda  Introduction  Background  Framework features review  Configuration  View technology  Page flow  Form binding  Table sorting  Pagination  Validation  AJAX  Error handling  I18n support  Documentation  Summary

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 3 Introduction::In a nutshell (1) Action Based MVC Framework –FilterDispatcher : controller –Action : POJO model –Result : view Comparable to –Struts1 –Spring MVC –Stripes

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 4 Introduction::In a nutshell (2) First released in Oct –Merger of Struts1 and WebWork2 –Uses WebWork2 architecture Modern and clean architecture Xml or annotations –Actions –Validators –Datatype convertors

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 5 Introduction::In a nutshell (3) Extensible via plugins –Other frameworks integration –Embedding other application modules Intuitive, fast learning curve Other core components –Interceptors: controlling action pre and post processing –ValueStack: central storage for request model data

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 6 Introduction::HelloWorld action2 org.apache.struts2.dispatcher.FilterDispatcher action2 /* Controller: FilterDispatcher web.xml

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 7 Introduction::HelloWorld, Model public class HelloWorld { private String message="Hello World. Time is: "; public String execute () { message += new Date(); return "success"; } public String getMessage() { return message; } action method returns a result code We don’t have to extend Action Boss … and no request, response in execute() Boss

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 8 Introduction::HelloWorld, View View: HelloWorld.jsp –Utilizes a single struts taglib –The taglib is common for JSP, Velocity and FreeMarker Prints action’s message property. Unlike struts1, action is a POJO, and acts as a model

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 9 Introduction::HelloWorld /pages/HelloWorld.jsp struts.xml: –Actions mapping –Results mapping links action to view Use action name in URL invocation

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 10 Agenda  Introduction  Background  Framework features review  Configuration  View technology  Page flow  Form binding  Table sorting  Pagination  Validation  AJAX  Error handling  I18n support  Documentation  Summary

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 11 Background::S2 Vs. S1 Struts1Struts2 Extends ActionActionPOJO (with execute) ControllerAction RoleModel DependantServlet APIDecoupled Single instanceThreadingInstance per request Action FormForm bindingAction JavaBean properties JSP mechanismsView bindingValue Stack JSTL ELELOGNL Action FormValidationxml or annotations SharedLifecycleIndependent via interceptors VerboseConfigurationWildcards, annotations

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 12 Background::Interceptors Actions pre & post processing mechanism Like Spring AOP, EJB3 interceptors Interceptors are packed in stacks Custom interceptors and stacks can be added No equivalent in Struts1 /pages/phoneBook.jsp struts.xml

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 13 Background::Interceptors Excerpt from struts-default.xml interceptor interceptor stack contains other interceptors the default stack for actions in package struts-default.xml

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 14 Background::ValueStack The ValueStack is a storage for request domain model Serves as context per request “Glues” model and view Accessed by interceptors & views Stores action properties Also stores message bundles

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 15 Background::OGNL ValueStack is referenced and manipulated by OGNL OGNL is also used instead of JSTL <s:textfield name="contact. "/> <s:text name=" "/> phoneBook.jsp retrieves property of actions’ contact property from stack using OGNL retrieves localized message using as key from stack using OGNL

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 16 Background::Other features Tag Library –Form component tags –Ajax UI component tags –Control tags: iterator, if/else… –Data tags: manipulate the ValueStack Datatype conversion framework Themes: templates for customizing components markup

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 17 Background:: Theme example Xhtml theme generates table and validation feedback. No themes in Struts1 login.jsp

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 18 Background::Other features Reasonable defaults: struts-default –Result types –Interceptor stacks Actions extending ActionSupport –facilitates validation –facilitates localization Spring integration –Dependency Injection interceptor –Full Spring lifecycle management

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 19 Agenda  Introduction  Background  Framework features review  Configuration  View technology  Page flow  Form binding  Table sorting  Pagination  Validation  AJAX  Error handling  I18n support  Documentation  Summary

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 20 Features::Action Configuration /WEB-INF/list.jsp result type the view technology (default value: “dispatcher” for rendering JSP) result name action method should return a matching result code string (default value: “success”) action method within action class (default value: “execute”) action class action name matched by a URL

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 21 Features:: Action Configuration /WEB-INF/list{1}s.jsp Wildcards can be used for mapping Mandates naming convention Makes XML much less verbose listEmployees.action is mapped to Employee class and listEmployees.jsp listDepartments.action is mapped to Department class and listDepartmrnts.jsp …

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 22 Features::Annotation "list", value="/WEB-INF/list.jsp") public class Employee extends ActionSupport { public String listEmployees() { // business logic goes here return "list" ; } Annotation based configuration –Can make XML utterly redundant –Struts scans packages for action classes –Results are expressed “list” result code is mapped to JSP. By extending ActionSupport, Employee is mapped as action by the package scanning mechanism

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 23 Features::View technology Result types –JSP : dispatcher –Velocity –FreeMarker –XSLT –Stream : PDF, MS Word etc. Plugins –JasperReports –JFreeChart –JSON

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 24 Features::Page flow

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 25 Features::Page flow 1.User Sends HTTP request 2.FilterDispatcher determines appropriate action 3.Interceptors are applied 4.Action parameters are set (via params interceptor) 5.Action is being executed 6.The Result (view) renders the output 7.Optionaly: the view retrieves data from action 8.The result is displayed to the user

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 26 Features::Form binding <s:form action="login" validate="true" namespace="/"> <s:textfield cssClass="loginField" key= "username" /> <s:submit key="login" cssClass="button" align="center"/> </s:form> login.jsp public class Login { private String username; public void setUsername(String username) { this.username = username; } Login.java Form field parameters are injected into setter methods by the params interceptor

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 27 Features::Table sorting 1.Using Table Tags plugin –Undocumented –Looks inactive –Lack of evidence 2.Using Dojo + JSON –Too complex 3.YUI DataTable –Buggy, beta 4.Display tag library

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 28 Features::Table sorting From demo application phoneBook.jsp

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 29 Features::Pagination Used the display tag library internal pagination support –Supports internal and external pagination –Forces you to use HTTP GET –Adds pagination parameter to request

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 30 Features::Validation Uses 12 out-of-box field validators Uses expression validators for complex validations Validators can be declared using xml Validators can be declared using annotations –Field validators for setter methods –Expression validator for action methods

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 31 fieldName = " ", key="wrong Format", message="Wrong Format") public void set (String ) { this. = ; } PhoneBook.java Wrong Format PhoneBook_validation.xml Annotation vs. xml example (No annotated version for Struts1)

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 32 Features::Client side validation Automatic creation of client side validation –No client side for expression validators –Apply a theme for generating error feedback markup login.jsp

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 33 Features::Ajax Dojo is embedded for Ajax tags Dojo head tag enables JS debugging Ajax requests are handled by actions DWR integration is enabled via plugin YUI integration is enabled via plugin Ajax file upload via plugin Ajax behaviour for component tags

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 34 Features::Ajax autocompleter View Action <s:url id="acUrl" action="getDepts"/> <s:autocompleter name="dept" href="%{acUrl}" cssClass="acSearchField"/> private List deptList; public String execute() { deptList = service.findAllDepartments(); return ActionSupport.SUCCESS; } public List getDeptList() { return deptList; } phoneBook.jsp PhoneBook.java <action name="getDepts" class="DeptsAutoComplete"> deptList struts-default.xml

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 35 Features::Error handling Validation error feedback tags –actionerror –actionmessage –fielderror: per form field Two framework supporting interfaces –Validatable: for programmatic validation –ValidationAware: for UI feedback

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 36 Features::Error handling /pages/systemError.jsp Exception interceptor –maps exceptions to result error pages –should be first in interceptor stack struts.xml

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 37 Features::I18N support Built on top of Java I18N support Bundles can be defined in: –action.properties –package.properties –global resource properties Bundles pushed to ValueStack Validation errors can be localized Locale interceptor to switch locale

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 38 Features::Documentation Apache Struts 2 Documentation WIKI Struts Showcase Plugins

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 39 Agenda  Introduction  Background  Framework features review  Configuration  View technology  Page flow  Form binding  Table sorting  Pagination  Validation  AJAX  Error handling  I18n support  Documentation  Summary

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 40 Summary::Pros Extensible plugin framework Modular and clean architecture Annotation or xml configuration Customized lifecycle via interceptors Neat form & view binding Easy client side validation Markup generation with themes

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 41 Summary::Pros Fast learning curve Intuitive Restful URL action mapper Easy to test (POJOs) using plugins DI via lightweight containers Decoration with tiles, sitemash

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 42 Summary::Cons Unorganized documentation Lack of API documentation No clear roadmap ActionSupport dependency Lack Lack Cases when fallback to Servlet API is needed Weakly typed sessions

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 43 Summary::When to use Use when –Migrating from legacy framework –Natural around HTTP request response paradigm –Suitable for streaming –POC, prototype, RAD Don’t use when –Heavily utilized RIA is needed –Your developers have Swing orientation

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar 44 Thank You !