Web Frameworks and WebWork



Similar documents
Model-View-Controller. and. Struts 2

Java and Web. WebWork

Web Applications and Struts 2

In this chapter, we lay the foundation for all our further discussions. We start

Web Container Components Servlet JSP Tag Libraries

Complete Java Web Development

Web Applications. For live Java training, please see training courses at

DTS Web Developers Guide

Pentesting Web Frameworks (preview of next year's SEC642 update)

An introduction to creating JSF applications in Rational Application Developer Version 8.0

Servlet 3.0. Alexis Moussine-Pouchkine. mercredi 13 avril 2011

Web Applications. Originals of Slides and Source Code for Examples:

Creating Java EE Applications and Servlets with IntelliJ IDEA

Course Name: Course in JSP Course Code: P5

Web Programming II JSP (Java Server Pages) ASP request processing. The Problem. The Problem. Enterprise Application Development using J2EE

JBoss Portlet Container. User Guide. Release 2.0

Developing Web Applications using JavaServer Pages and Servlets

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Web Presentation Layer Architecture

Hello World Portlet Rendered with JSP for WebSphere Portal Version 4.1

PowerTier Web Development Tools 4

BIRT Application and BIRT Report Deployment Functional Specification

Tutorial: Building a Web Application with Struts

Drupal CMS for marketing sites

How To Understand The Architecture Of Java 2Ee, J2Ee, And J2E (Java) In A Wordpress Blog Post

Course Number: IAC-SOFT-WDAD Web Design and Application Development

JBoss SOAP Web Services User Guide. Version: M5

CREATE A CUSTOM THEME WEBSPHERE PORTAL

CrownPeak Java Web Hosting. Version 0.20

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

Getting Started with Web Applications

Aspect Oriented Programming. with. Spring

Reporting and JSF. Possibilities, solutions, challenges. Slide 1. Copyright 2009, Andy Bosch,

Design and Functional Specification

SESM Tag Library. Configuring a Tag Library APPENDIX

Sightly Component Development

Web Application Architecture (based J2EE 1.4 Tutorial)

An introduction to web programming with Java

Spring Security SAML module

Servlet and JSP Filters

Enterprise Application Development In Java with AJAX and ORM

Outline. CS 112 Introduction to Programming. Recap: HTML/CSS/Javascript. Admin. Outline

Development. with NetBeans 5.0. A Quick Start in Basic Web and Struts Applications. Geertjan Wielenga

<Insert Picture Here> Hudson Security Architecture. Winston Prakash. Click to edit Master subtitle style

Struts Tools Tutorial. Version: M5

Oracle Hyperion Financial Management Custom Pages Development Guide

Controlling Web Application Behavior

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

SSC - Web development Model-View-Controller for Java web application development

2. Follow the installation directions and install the server on ccc

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports Server 6i

zen Platform technical white paper

Glassfish, JAVA EE, Servlets, JSP, EJB

Proposal for DSpace Web MVC

MVC pattern in java web programming

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Agenda. Summary of Previous Session. Application Servers G Session 3 - Main Theme Page-Based Application Servers (Part II)

Software project management. and. Maven

Maven 2 in the real world

What means extensibility?

Esigate Module Documentation

Design Approaches of Web Application with Efficient Performance in JAVA

Server Setup and Configuration

Mastering Tomcat Development

Certified PHP/MySQL Web Developer Course

Crawl Proxy Installation and Configuration Guide

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

Stock Trader System. Architecture Description

Security Code Review- Identifying Web Vulnerabilities

Alfresco. Wiley Publishing, Inc. PROFESSIONAL. PRACTICAL SOLUTIONS FOR ENTERPRISE. John Newton CONTENT MANAGEMENT. Michael Farman Michael G.

Java Servlet 3.0. Rajiv Mordani Spec Lead

Developer Tutorial Version 1. 0 February 2015

Customer Bank Account Management System Technical Specification Document

Install guide for Websphere 7.0

Services. Custom Tag Libraries. Today. Web Development. Role-Based. Development. Code Reuse. Tag Libraries Custom Tags. Tag Lifecycle.

Oracle Hyperion Financial Management Developer and Customization Guide

MarkLogic Server. Reference Application Architecture Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

S3 Monitor Design and Implementation Plans

JSP Java Server Pages

Server-Side Web Development JSP. Today. Web Servers. Static HTML Directives. Actions Comments Tag Libraries Implicit Objects. Apache.

Intellicus Single Sign-on

Software project management. and. Maven

Expert Spring MVC and Web Flow

Cache Configuration Reference

NextRow - AEM Training Program Course Catalog

HPC Portal Development Platform with E-Business and HPC Portlets

ACM Crossroads Student Magazine The ACM's First Electronic Publication

Introduction to J2EE Web Technologies

Web Application Development

Software Development Kit

Liferay Enterprise ecommerce. Adding ecommerce functionality to Liferay Reading Time: 10 minutes

Application Notes for Packaging and Deploying Avaya Communications Process Manager Sample SDK Web Application on a JBoss Application Server Issue 1.

Building Web Services with Apache Axis2

Transcription:

Web Frameworks and WebWork

Problem area Mixing application logic and markup is bad practise Harder to change and maintain Error prone Harder to re-use public void doget( HttpServletRequest request, HttpServletResponse response ) { PrintWriter out = response.getwriter(); out.println( <html>\n<body> ); if ( request.getparameter( foo ).equals( bar ) ) out.println( <p>foo is bar!</p> ); else out.println( <p>foo is not bar!</p> ); } out.println( </body>\n</html> );

Advantages Separation of application logic and web design through the MVC pattern Integration ti with template t languages Some provides built-in components for Form validation Error handling Internationalization IDE integration

The MVC pattern Breaks an application into three parts: Model: The domain object model / service layer View: Template code/markup Controller: Presentation logic/action classes Defines interaction between components to promote loose coupling and re-use Each file has one responsibility Enables division of labour between programmers and designers

WebWork Sophisticated web framework Latest version is 2.2.6 project merged with Struts Built on top of XWork a command pattern framework Can be integrated with object factories like Spring Required libraries webwork commons-logging velocity + velocity-tools servlet-api

MVC with Front Controller Front controller. Maps request URLs to controller classes. Implemented as a servlet. Web browser. Displays output. Web page template like JSP or Velocity. Command instances/ Action classes. Interacts with backend services of the system. Backend services working with the API/ data model.

Action Flow Response to client (random.vm) Result Client HTTP request to URL (getrandomstring.action) web.xml Stack of interceptors xwork.xml WebWork Stack of Action classes (config file) Servlet dispatcher interceptors (User code) (GetRandomStringAction.java)

Web.xml Maps URL patterns to the WebWork dispatcher Most typical pattern is *.action Located in WEB-INF/ folder Can redirect to the Filter- or ServletDispatcher <filter> <filter-name>webwork</filter-name> <filter-class>com.opensymphony.webwork.dispatcher.filterdispatcher</filter-class> </filter> <filter-mapping> <filter-name>webwork</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>

Xwork.xml Located in root of classpath Must include webwork-default.xml Maps URLs to action classes Maps result codes to results <xwork> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> <action name= invertstring" class="no.uio.inf5750.example.action.invertstringaction"> <result name="success" type="velocity">word.vm</result> </action> </package> </xwork>

Action classes Java code executed when a URL is requested Must implement the Action interface or extend ActionSupport t Provides the execute method Must return a result code (SUCCESS, ERROR, INPUT) Used to map to results Properties es set by the request through public set-methodse Properties made available to the response through public get-methods

Action classes HTTP request getrandomstring.action?word=someenteredword public class InvertStringAction Implements Action implements Action { private String word; Must correspond to public void setword( String word ) { request parameter, this.word = word; exposed through set-method } Must correspond to property name in view, exposed through get-method Execute method with user code private String invertedword; public String getinvertedword() { return this.invertedword; i t d } public String execute() { char[] chars = word.tochararray(); // do some inverting here... Must return a result code (defined in Action) } } invertedword = buffer.tostring(); return SUCCESS;

View WebWork integrates with many view technologies JSP Velocity Freemarker JasperReports p Values sent to controller with POST or GET as usual Values made available a ab to the view by the controllero

View Velocity is a popular template engine and -language Java Action class public String getinvertedword() t d() { return this.invertedword; } <html> Form action to URL mapped in xwork.xml Input name corresponding to set-method in action class Velocity yparameter corresponding to get-method in action class <body> <form method= post action= invertstring invertstring.action action > > <p><input type= text name= word ></p> <p><input type= submit value= Invert ></p> </form> <p>$invertedword</p> </body> </html>

Xwork.xml advanced (1) Different result codes can be mapped to different results <xwork> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> <action name= invertstring" class="no.uio.inf5750.example.action.invertstringaction"> <result name="success" type="velocity">word.vm</result> <result name= input type= velocity >input.vm</result> </action> </package> </xwork>

Xwork.xml advanced (2) Static parameters can be defined Requires public set-methods in action classes WebWork provides automatic type conversion <xwork> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> <action name= invertstring" class="no.uio.inf5750.example.action.getrandomstringaction"> <result name="success" type="velocity">random.vm</result> <param name= numberofchars >32</param> </action> </package> </xwork>

Xwork.xml advanced (3) Xwork.xml files can include other files Files are merged Facilitates t breaking complex applications into manageable modules Specified files are searched for in classpath Configuration can be separated in multiple files / JARs <xwork> <include file="webwork-default.xml"/> <package name= default" extends= webwork-default > <! Default action mappings --> </package> <include file= xwork-public.xml /> <include file= xwork-secure.xml /> </xwork>

Xwork.xml advanced (4) Actions can be grouped in packages Useful for large systems to promote modular design A package can extend other packages Definitions from the extended package are included Configuration of commons elements can be centralizeded <xwork> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> <action name= invertstring class= no.uio.no.example.action.invertstringaction > <! mapping omitted --> </action> </package> <package name= secure extends= default > <! Secure action mappings --> </package> </xwork>

Xwork.xml advanced (5) Actions can be grouped in namespaces Namespaces map URLs to actions Actions identified by the name and the namespace it belongs to Facilitates modularization and maintainability <xwork> <include file="webwork-default.xml"/> <package name= secure" extends= default namespace= /secure > <action name= getusername class= no.uio.inf5750.example.action.getusernameaction > <result name= success type= velocity >username.vm</result> </action> </package> </xwork>

Interceptors Invoked before and/or after the execution of an action Enables centralization of concerns like security, logging <xwork> <include file="webwork webwork-default.xml xml"/> <package name="default" extends="webwork-default"> <interceptors> <interceptor name= profiling class= no.uio.example.interceptor.profilinginterceptor /> </interceptors> <action name= invertstring class= no.uio.no.example.action.invertstringaction > <result name= success type= velocity >word.vm</result> y <interceptor-ref name= profiling /> </action> </package> </xwork>

Provided interceptors Interceptors perform many tasks in WebWork ParametersInterceptor (HTTP request params) StaticParametersInterceptor (config params) ChainingInterceptor Many interceptor stacks provided in webwork-default.xml defaultstack i18nstack fileuploadstack and more

Interceptor stacks Interceptors should be grouped in stacks A default interceptor stack can be defined Should include the WebWork default stack <xwork> <! include file and package omitted --> <interceptors> <interceptor name= profiling class= no.uio.example.interceptor.profilinginterceptor /> <interceptor name= logging class= no.uio.example.logging.logginginterceptor /> <interceptor-stack name= examplestack > <interceptor-ref name= defaultstack /> <interceptor-ref name= profiling /> <interceptor-ref name= logging /> </interceptor-stack> </interceptors> <default-interceptor-refp name= examplestack /> </xwork>

Result types Determines behaviour after the action is executed and the result is returned Several result types bundled d with WebWork Dispatcher (JSP) Default -will generate a JSP view Velocity Will generate a Velocity view Redirect Will redirect the request to the specified action after execution Chain Same as redirect but makes all parameters available to the p following action

Result types Chain result type. The properties in GetRandomStringAction will be available for InvertStringAction. Redirect result type. Redirects the request to another action after being executed. Velocity result type. <xwork> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> <action name= getrandomstring class= no.uio...getrandomstringaction > <result name= success type= chain >invertstring</result> <result name= input type= redirect >error.action</result> </action> <action name= invertstring class= no.uio...invertstringaction > <result name= success type= velocity >word.vm</result> </action> </package> </xwork> Generates a HTML response based on a Velocity template.

Result types Several provided result types integrated with ext tools JasperReports Flash Freemarker Custom result types can be defined <xwork> <include name= webwork-default.xml /> <package name= default extends= webwork-default > <result-types> <result-type name= velocityxml class= no.uio.inf5750.example.xmlresult /> </result-types> </package> </xwork> } public class XMLResult implements Result { public void execute( ActionInvocation invocation ) { Action action = invocation.getaction(); } // Print to HTTPServletResponse or // modify action parameters or whatever..

IoC WebWork has its own IoC container - deprecated Should be integrated with third party containers (Spring) webwork.properties webwork.objectfactory = spring xwork.xml The class property in action mappings will refer to Spring bean ids instead of classes. <xwork> <! Include file and package omitted --> <action name= getrandomstring class= getrandomstringaction > <result name= success type= chain >invertstring</result> </action> </xwork> beans.xml Spring configuration file. <bean id= getrandomstringaction class= no.uio.inf5750.example.action.getrandomstringaction />

Velocity Velocity is a template language Template: basis for documents with similar structure Template language: format defining where variables should be replaced in a document Features include: Variable replacement Simple control structures Method invocation Velocity result is included in webwork-default.xml Velocity is a runtime language Fast Error prone

Velocity Variable replacement Control structures <html> <head><title>$word</title></head> <body> #if ( $word == Hello ) <div style= background-color: red > #elseif ( $word == Goodbye ) <div style =background-color: blue > #else <div> #end Method call $word.substring( 10) </div> Loop #foreach ( $word in $words ) <p>$word</p> #end </body> </html>

WebWork in DHIS 2 WebWork support project (dhis-support-webwork) Filters Application logic interceptors Custom results Webwork commons project (dhis-web-commons) Java code for widgets, security, portal Interceptor, result configuration Packaged as JAR file Webwork commons resources project (dhis-webcommons-resource ) Web resources like templates, javascripts, css Packaged as WAR file

Web modules in DHIS 2 Templates included in backbone template main.vm Static params in WebWork configuration Must depend d on dhis-web-commons and dhis-webcommons-resources XWork package must Include and extend dhis-web-commons.xml instead of webworkdefault.xml Have the same package name as the artifact id Have the same namespace as the artifact id Development tip: $ mvn jetty:run war Packages and deploys war file to Jetty for rapid development

Resources Patrick Lightbody, Jason Carreira: WebWork in Action Velocity user guide: http://velocity.apache.org/engine/devel/user-guide.html Webwork self study Taglibs Internationalisation Validation