• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Migrating to Struts2 of Struts1
 

Migrating to Struts2 of Struts1

on

  • 3,813 views

 

Statistics

Views

Total Views
3,813
Views on SlideShare
3,794
Embed Views
19

Actions

Likes
1
Downloads
160
Comments
1

2 Embeds 19

http://cdiaz1986.tumblr.com 18
http://www.techgig.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Migrating to Struts2 of Struts1 Migrating to Struts2 of Struts1 Presentation Transcript

    • Migrating to Struts 2A tutorial for Struts 1 Developers Struts University Series
    • Migrating to Struts 2A tutorial for Struts 1 Developers Struts University Series
    • Ted? Whos Ted?Apache Software Foundation MemberApache Struts & Apache iBATIS PMCsJUnit in Action, Struts in Action, andProfessional JSP Site DesignConsult with teams throughout theUnited StatesStill working with the OK DEQ
    • Ted? Whos Ted?Apache Software Foundation MemberApache Struts & Apache iBATIS PMCsJUnit in Action, Struts in Action, andProfessional JSP Site DesignConsult with teams throughout theUnited StatesStill working with the OK DEQ
    • Ted? Whos Ted?Apache Software Foundation MemberApache Struts & Apache iBATIS PMCsJUnit in Action, Struts in Action, andProfessional JSP Site DesignConsult with teams throughout theUnited StatesStill working with the OK DEQ
    • Ted? Whos Ted?Apache Software Foundation MemberApache Struts & Apache iBATIS PMCsJUnit in Action, Struts in Action, andProfessional JSP Site DesignConsult with teams throughout theUnited StatesStill working with the OK DEQ
    • Ted? Whos Ted?Apache Software Foundation MemberApache Struts & Apache iBATIS PMCsJUnit in Action, Struts in Action, andProfessional JSP Site Design.Consult with teams throughout theUnited StatesStill working with the OK DEQ
    • Ted? Whos Ted?Apache Software Foundation MemberApache Struts & Apache iBATIS PMCsJUnit in Action, Struts in Action, andProfessional JSP Site Design.Consult with teams throughout theUnited StatesStill working with the OK DEQ
    • Migrating to Struts 2Help Struts 1 developers becomeknowledgeable Struts 2 developers asquickly as possibleMigrate Struts 1 application to Struts 2Intended for experienced Java webdevelopers
    • Migrating to Struts 2Help Struts 1 developers becomeknowledgeable Struts 2 developers asquickly as possibleMigrate Struts 1 application to Struts 2Intended for experienced Java webdevelopers
    • Migrating to Struts 2Help Struts 1 developers becomeknowledgeable Struts 2 developers asquickly as possibleMigrate Struts 1 application to Struts 2Intended for experienced Java webdevelopers
    • Migrating to Struts 2Help Struts 1 developers becomeknowledgeable Struts 2 developers asquickly as possibleMigrate Struts 1 application to Struts 2Intended for experienced Java webdevelopers
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • Baseline QuestionsWhat is Struts 2?How are Struts 1 and Struts alike?Whats changed in Struts 2?Is Struts 1 obsolete?Is it difficult to migrate?Why are "plain old Java objects" important?Where should a migration begin?
    • What is Struts 2?Free open-source framework Two major versionsStruts 1 Proven solution to common problemsStruts 2 Elegant solution to difficult problems
    • What is Struts 2?Free open-source framework Two major versionsStruts 1 Proven solution to common problemsStruts 2 Elegant solution to difficult problems
    • What is Struts 2?Free open-source framework Two major versionsStruts 1 Proven solution to common problemsStruts 2 Elegant solution to difficult problems
    • What is Struts 2?Free open-source framework Two major versionsStruts 1 Proven solution to common problemsStruts 2 Elegant solution to difficult problems
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA tag library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA tag library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA tag library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA tag library  creates rich, form-based applications
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats changed in Struts 2?Smarter! Improved Design Intelligent Defaults Enhanced Results Enhanced Tags First-class AJAX support Stateful Checkboxes QuickStart
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2?Easier! Easy-to-test Actions Easy-to-customize controller Easy-to-tweak tags Easy cancel handling Easy Spring integration Easy plugins
    • Whats Changed in Struts 2POJO-ier! POJO forms POJO Actions
    • Whats Changed in Struts 2POJO-ier! POJO forms POJO Actions
    • Whats Changed in Struts 2POJO-ier! POJO forms POJO Actions
    • Is Struts 1 obsolete?Robust and vibrant communityThousands of applications in productionNew 1.3.5 releaseBut, is it time to try Struts 2?
    • Is Struts 1 obsolete?Robust and vibrant communityThousands of applications in productionNew 1.3.5 releaseBut, is it time to try Struts 2?
    • Is Struts 1 obsolete?Robust and vibrant communityThousands of applications in productionNew 1.3.5 releaseBut, is it time to try Struts 2?
    • Is Struts 1 obsolete?Robust and vibrant communityThousands of applications in productionNew 1.3.5 releaseBut, is it time to try Struts 2?
    • Is Struts 1 obsolete?Robust and vibrant communityThousands of applications in productionNew 1.3.5 releaseBut, is it time to try Struts 2?
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investment
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investment
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investment
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investment
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investment
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investmentStruts 2 is smarter, easier
    • Is it difficult to migrate?Not difficult but non-trivialMigrating Actions takes time and effortStable: may not be worth the effortGrowth: good investmentStruts 2 is smarter, easier, and POJO-ier
    • Why are POJOs important?No "extra" objects Instantiate Actions with new or Spring Simulate servlet state with HashMapRich input properties No ActionForms! Use Action or any other object Non-String properties are not a problem
    • Why are POJOs important?No "extra" objects Instantiate Actions with new or Spring Simulate servlet state with HashMapRich input properties No ActionForms! Use Action or any other object Non-String properties are not a problem
    • Why are POJOs important?No "extra" objects Instantiate Actions with new or Spring Simulate servlet state with HashMapRich input properties No ActionForms! Use Action or any other object Non-String properties are not a problem
    • Struts University Series
    • How are Struts 1 and Struts 2 alike?A "r******" handler  maps Java classes to web application URIsA "r*******" handler  maps logical names to web resourcesA *** library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "r*******" handler  maps logical names to web resourcesA *** library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA *** library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA tag library  creates rich, form-based applications
    • How are Struts 1 and Struts 2 alike?A "request" handler  maps Java classes to web application URIsA "response" handler  maps logical names to web resourcesA tag library  creates rich, form-based applications
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Add Struts 2 JARsMigrate application page at a timeUse both versions at the same timeArchitectures can remain the sameRemove Struts 1 red tapeSwap in new tags
    • Where should a migration begin?Migrate "Hello World" applicationDisplays message in two languagesAdd input form for custom messageValidate data entry
    • Where should a migration begin?Migrate "Hello World" applicationDisplays message in two languagesAdd input form for custom messageValidate data entry
    • Where should a migration begin?Migrate "Hello World" applicationDisplays message in two languagesAdd input form for custom messageValidate data entry
    • Where should a migration begin?Migrate "Hello World" applicationDisplays message in two languagesAdd input form for custom messageValidate data entry
    • Where should a migration begin?Update web.xml to add ...1)The Struts 2 Filter2)A filter mapping3)The Spring Listener
    • Where should a migration begin?Update web.xml to add ...1)The Struts 2 Filter2)A filter mapping3)The Spring Listener
    • Where should a migration begin?Update web.xml to add ...1)The Struts 2 Filter2)A filter mapping3)The Spring Listener
    • Where should a migration begin?Update web.xml to add ...1)The Struts 2 Filter2)A filter mapping3)The Spring Listener
    • Where should a migration begin?Update web.xml to add ...1)The Struts 2 Filter2)A filter mapping3)The Spring Listener
    • <web-app> <!-- Struts 2 --> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping><filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
    • <!-- Struts 1 --><servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/classes/struts-config.xml </param-value> </init-param> <load-on-startup>2</load-on-startup></servlet><servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern></servlet-mapping>
    • <!-- Either version --> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list></web-app>
    • applicationContext.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans></beans>
    • Lets code it!
    • Where should a migration begin?Struts 1 actions handle *.doStruts 2 actions handle *.actionMigrate one to the other,until theres nothing left to "do"!
    • Where should a migration begin?Struts 1 actions handle *.doStruts 2 actions handle *.actionMigrate one to the other,until theres nothing left to "do"!
    • Where should a migration begin?Struts 1 actions handle *.doStruts 2 actions handle *.actionMigrate one to the other,until theres nothing left to "do"!
    • Where should a migration begin?Struts 1 actions handle *.doStruts 2 actions handle *.actionMigrate one to the other,until theres nothing left to "do"!
    • Struts University Series
    • Where should a migration begin?For dependency injection, by default,Struts 2 uses HiveMind Spring Castle Pico
    • Where should a migration begin?For dependency injection, by default,Struts 2 uses HiveMind Spring Castle Pico
    • Where should a migration begin?Update web.xml to add ... The Struts 2 ****** A filter ******* The ****** Listener
    • Where should a migration begin?Update web.xml to add ... The Struts 2 ****** A filter ******* The ****** Listener
    • Where should a migration begin?Update web.xml to add ... The Struts 2 Filter A filter ******* The ****** Listener
    • Where should a migration begin?Update web.xml to add ... The Struts 2 Filter A filter mapping The ****** Listener
    • Where should a migration begin?Update web.xml to add ... The Struts 2 Filter A filter mapping The Spring Listener
    • Where should a migration begin?Update web.xml to add ... The Struts 2 Filter A filter mapping The Spring Listener
    • Is the Struts 2 configuration file different? Struts 2 configuration file is streamlined Less to configure Element names are shorter Struts 1 is "struts-config.xml" Struts 2 is "struts.xml"
    • Is the Struts 2 configuration file different? Struts 2 configuration file is streamlined Less to configure Element names are shorter Struts 1 is "struts-config.xml" Struts 2 is "struts.xml"
    • Is the Struts 2 configuration file different? Struts 2 configuration file is streamlined Less to configure Element names are shorter Struts 1 is "struts-config.xml" Struts 2 is "struts.xml"
    • Is the Struts 2 configuration file different? Struts 2 configuration file is streamlined Less to configure Element names are shorter Struts 1 is "struts-config.xml" Struts 2 is "struts.xml"
    • Is the Struts 2 configuration file different? Struts 2 configuration file is streamlined Less to configure Element names are shorter Struts 1 is "struts-config.xml" Struts 2 is "struts.xml"
    • Is the Struts 2 configuration file different? Struts 2 configuration file is streamlined Less to configure Element names are shorter Struts 1 is "struts-config.xml" Struts 2 is "struts.xml"
    • <?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"><struts-config> <form-beans> <form-bean name="HelloForm" type="actions.HelloForm"> </form-bean> </form-beans> <action-mappings> <action path="/Hello" name="HelloForm" type="actions.HelloAction" validate="false"> <forward name="success" path="/HelloPage.jsp"/></action> </action-mappings> <message-resources parameter="resources"/></struts-config>
    • <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <include file="struts-default.xml"/> <package name="hello-default" extends="struts-default"> <action name="Hello" class="actions.Hello"> <result>/Hello.jsp</result> </action> </package></struts>
    • Lets code it!
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationTo update each <action> element, we1)Remove from <action> the "name" attribute2)Change the <action> "path" attribute to "name", and "type" to "class"3)Change the <forward> element into a <result> element.
    • To migrate configurationTo update each <action> element, we1)Remove from <action> the "name" attribute2)Change the <action> "path" attribute to "name", and "type" to "class"3)Change the <forward> element into a <result> element.
    • To migrate configurationTo update each <action> element, we1)Remove from <action> the "name" attribute2)Change the <action> "path" attribute to "name", and "type" to "class"3)Change the <forward> element into a <result> element.
    • To migrate configurationTo update each <action> element, we1)Remove from <action> the "name" attribute2)Change the <action> "path" attribute to "name", and "type" to "class"3)Change the <forward> element into a <result> element.
    • Struts University Series
    • Is the Struts 2 configuration file different? Struts 2 configuration file is (less/more) to configure Struts 2 configuration file is named "******.xml" Most Struts 2 configurations include the “struts-*******.xml”
    • Is the Struts 2 configuration file different? Struts 2 configuration file is (less/more) to configure Struts 2 configuration file is named "******.xml" Most Struts 2 configurations include the “struts-*******.xml”
    • Is the Struts 2 configuration file different? Struts 2 configuration file is (less/more) to configure Struts 2 configuration file is named "struts.xml" Most Struts 2 configurations include the “struts-*******.xml”
    • Is the Struts 2 configuration file different? Struts 2 configuration file is (less/more) to configure Struts 2 configuration file is named "struts.xml" Most Struts 2 configurations include the “struts-default.xml”
    • Is the Struts 2 configuration file different? Struts 2 configuration file is (less/more) to configure Struts 2 configuration file is named "struts.xml" Most Struts 2 configurations include the “struts-default.xml”
    • To migrate configurationReplace the DTD****** <struts-config> to <struts>Add <include file="struts-default.xml"/>****** the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">****** each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>****** the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">****** each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">****** each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • To migrate configurationReplace the DTDChange <struts-config> to <struts>Add <include file="struts-default.xml"/>Remove the <form-beans> elementChange <action-mappings> to<package name="hello-default"extends="struts-default">Update each <action> element
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are applied consistentlyComprehension Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are applied consistentlyComprehension Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are applied consistentlyComprehension Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are applied consistentlyComprehension Concise and easier to understand
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a predefined value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a predefined value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a predefined value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a predefined value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent Defaults<forward name="success" path="/Hello.jsp"/><result>/Hello.jsp</result> The <result> name defaults to "success" The <result> content defaults to "location" (e.g. path) The <result> type defaults to "dispatch"
    • Intelligent Defaults<forward name="success" path="/Hello.jsp"/><result>/Hello.jsp</result> The <result> name defaults to "success" The <result> content defaults to "location" (e.g. path) The <result> type defaults to "dispatch"
    • Intelligent Defaults<forward name="success" path="/Hello.jsp"/><result>/Hello.jsp</result> The <result> name defaults to "success" The <result> content defaults to "location" (e.g. path) The <result> type defaults to "dispatch"
    • Intelligent Defaults<result name="cancel" type="redirect"> /Welcome.jsp</result> Changing the result name and type
    • Struts University Series
    • Why so many changes?O******** We just plain dont need them anymoreC********** Attribute names are uniformC************ Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreC********** Attribute names are uniformC************ Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are uniformC************ Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are uniformComprehension Concise and easier to understand
    • Why so many changes?Obsolesce We just plain dont need them anymoreConsistency Attribute names are uniformComprehension Concise and easier to understand
    • Intelligent DefaultsWhen an ********* value is omitted, the system automatically provides a ********** value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a ********** value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a predefined value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Intelligent DefaultsWhen an essential value is omitted, the system automatically provides a predefined value, eliminating the need to explicitly qualify each and every aspect of a declaration. (Adapted from the CULE Knowledgebase)
    • Do Action classes change too? Mostly simpler Can combine Struts 1 ActionForm,  Add input properties directly to Action  Or, use POJO
    • Do Action classes change too? Mostly simpler Can combine Struts 1 ActionForm,  Add input properties directly to Action  Or, use POJO
    • Do Action classes change too? Mostly simpler Can combine Struts 1 ActionForm,  Add input properties directly to Action  Or, use POJO
    • package forms;import org.apache.struts.action.ActionForm;public class HelloForm extends ValidatorForm { private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }}
    • package actions;import javax.servlet.http.*;import org.apache.struts.action.*;public class HelloAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HelloForm input = (HelloForm) form; input.setMessage(MESSAGE); return mapping.findForward(SUCCESS); } public static final String MESSAGE = "Hello World!"; public static final String SUCCESS = "success";}
    • package actions;import com.opensymphony.xwork2.ActionSupport;public class Hello extends ActionSupport { public String execute() throws Exception { setMessage(MESSAGE); return SUCCESS; } public static final String MESSAGE = "Hello World!"; private String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; }}
    • Lets code it!
    • Do Action classes change too? To convert our Hello World Action class 1) Update or remove imports. 2) Move input property to the Action ● Remove obsolete ActionForm 3) Extend ActionSupport 4) Reference input property directly 5) Remove SUCCESS static
    • Do Action classes change too? To convert our Hello World Action class 1) Update or remove imports. 2) Move input property to the Action ● Remove obsolete ActionForm 3) Extend ActionSupport 4) Reference input property directly 5) Remove SUCCESS static
    • Do Action classes change too? To convert our Hello World Action class 1) Update or remove imports. 2) Move input property to the Action ● Remove obsolete ActionForm 3) Extend ActionSupport 4) Reference input property directly 5) Remove SUCCESS static
    • Do Action classes change too? To convert our Hello World Action class 1) Update or remove imports. 2) Move input property to the Action ● Remove obsolete ActionForm 3) Extend ActionSupport 4) Reference input property directly 5) Remove SUCCESS static
    • Do Action classes change too? To convert our Hello World Action class 1) Update or remove imports. 2) Move input property to the Action ● Remove obsolete ActionForm 3) Extend ActionSupport 4) Reference input property directly 5) Remove SUCCESS static
    • Do Action classes change too? To convert our Hello World Action class 1) Update or remove imports. 2) Move input property to the Action ● Remove obsolete ActionForm 3) Extend ActionSupport 4) Reference input property directly 5) Remove SUCCESS static
    • Struts University Series
    • Do Action classes change too?Can combine Struts 1 **********Move ***** property to the ActionOr, use Plain Old Java ******Extend ******Support
    • Do Action classes change too? Can combine Struts 1 ActionForm Move ***** property to the Action Or, use Plain Old Java ****** Extend ******Support
    • Do Action classes change too? Can combine Struts 1 ActionForm Move input property to the Action Or, use Plain Old Java ****** Extend ******Support
    • Do Action classes change too? Can combine Struts 1 ActionForm Move input property to the Action Or, use Plain Old Java Object Extend ******Support
    • Do Action classes change too? Can combine Struts 1 ActionForm Move input property to the Action Or, use Plain Old Java Object Extend ActionSupport
    • Do Action classes change too? Can combine Struts 1 ActionForm, Move input property to the Action Or, use Plain Old Java Object Extend ActionSupport
    • What about the tags?
    • <%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %><html><head> <title>Hello World!</title></head><body> <h2><bean:write name="HelloForm" property="message"/></h2></body></html><%@ taglib prefix="s" uri="/struts-tags" %><html><head> <title>Hello World!</title></head><body> <h2><s:property value="message"/></h2></body></html>
    • <%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %><html><head> <title>Hello World!</title></head><body> <h2><bean:write name="HelloForm" property="message"/></h2></body></html><%@ taglib prefix="s" uri="/struts-tags" %><html><head> <title>Hello World!</title></head><body> <h2><s:property value="message"/></h2></body></html>
    • Lets code it!
    • What about the tags?Replace the <%@ taglib @%> directiveChange <bean:write /> to <s:property />
    • What about the tags?Replace the <%@ taglib @%> directiveChange <bean:write /> to <s:property />
    • What about the tags?Replace the <%@ taglib @%> directiveChange <bean:write /> to <s:property />
    • What about the tags?New tags streamline page <bean:write> needs ActionForm name <s:property> finds property automatically
    • What about the tags?New tags streamline page <bean:write> needs ActionForm name <s:property> finds property automatically
    • What about the tags?New tags streamline page <bean:write> needs ActionForm name <s:property> finds property automatically
    • Struts University Series
    • What about the tags?Change <bean:write /> to <s:******** />New tags streamline page <bean:write> needs ActionForm name <s:********> finds ******** automatically
    • What about the tags?Change <bean:write /> to <s:property />New tags streamline page <bean:write> needs ActionForm name <s:********> finds ******** automatically
    • What about the tags?Change <bean:write /> to <s:property />New tags streamline page <bean:write> needs ActionForm name <s:property> finds property automatically
    • What about the tags?Change <bean:write /> to <s:property />New tags streamline page <bean:write> needs ActionForm name <s:property> finds property automatically
    • Can we still localize messages? Struts 2 uses standard message bundle Existing bundle set in struts.propertiesstruts.custom.i18n.resources = resources resources.properties resources_es.properties resources_fr_CA.properties
    • Can we still localize messages? Struts 2 uses standard message bundle Existing bundle set in struts.propertiesstruts.custom.i18n.resources = resources resources.properties resources_es.properties resources_fr_CA.properties
    • Can we still localize messages? Struts 2 uses standard message bundle Existing bundle set in struts.propertiesstruts.custom.i18n.resources = resources resources.properties resources_es.properties resources_fr_CA.properties
    • resources.propertiesmessage = Hello Worldresources_es.propertiesmessage = ¡Hola Mundo!
    • Can we still localize messages?Lookup message by key in ActionSet localized message to property
    • Can we still localize messages?Lookup message by key in ActionSet localized message to property
    • public class HelloAction extends Action { public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HelloForm input = (HelloForm) form;- input.setMessage(MESSAGE);+ input.setMessage(getResources(+ request).getMessage(MESSAGE)); return mapping.findForward(SUCCESS); }- public static final String MESSAGE = "Hello World!";+ public static final String MESSAGE = "message"; public static final String SUCCESS = "success";}
    • public class Hello extends ActionSupport { public String execute() throws Exception {- setMessage(MESSAGE);+ setMessage(getText(MESSAGE)); return SUCCESS; }- public static final String MESSAGE = "Hello World!";+ public static final String MESSAGE = "message";}
    • Can we still localize messages?Tags can output localized messages,based on a keyLets change page title to look up message
    • Can we still localize messages?Tags can output localized messages,based on a keyLets change page title to look up message
    • <%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %> <html><head>- <title>Hello World!</title>+ <title><bean:message key="message"/></title> </head> <body> <h2><bean:write name="HelloForm" property="message"/></h2> </body></html> <%@ taglib prefix="s" uri="/struts-tags" %> <html><head>- <title>Hello World!</title>+ <title><s:text name="message"/></title> </head> <body> <h2><s:property value="message"/></h2> </body></html>
    • Lets code it!
    • Can we still localize messages?Lookup message by key in ActionSet localized message to propertyTags can output localized messages,based on a key
    • Can we still localize messages?Lookup message by key in ActionSet localized message to propertyTags can output localized messages,based on a key
    • Can we still localize messages?Lookup message by key in ActionSet localized message to propertyTags can output localized messages,based on a key
    • Struts University Series
    • Can we still localize messages?(A)setMessage(getText(MESSAGE));(B)input.setMessage( getResources(request).getMessage(MESSAGE));The Struts 1 statement is shown as (A) / (B).The Struts 2 statement is shown as (A) / (B).
    • Can we still localize messages?(A)setMessage(getText(MESSAGE));(B)input.setMessage( getResources(request).getMessage(MESSAGE));The Struts 1 statement is shown as (A) / (B).The Struts 2 statement is shown as (A) / (B).
    • Can we still localize messages?struts.custom.i18n.********* = resources
    • Can we still localize messages?struts.custom.i18n.resources = resources
    • How do we change Locales?Locale is stored in users sessionStruts 1 requires a special Action
    • How do we change Locales?Locale is stored in users sessionStruts 1 requires a special Action
    • How do we change Locales?Locale is stored in users sessionStruts 1 requires a special Action
    • public final class LocaleAction extends Action { private static final String LANGUAGE = "language"; private static final String COUNTRY = "country"; private static final String SUCCESS = "success"; public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String language = request.getParameter(LANGUAGE); String country = request.getParameter(COUNTRY); Locale locale = getLocale(request); if ((language != null && language.length() > 0) && (country != null && country.length() > 0)) { locale = new java.util.Locale(language, country); } else if (language != null && language.length() > 0) { locale = new java.util.Locale(language, ""); } setLocale(request, locale); return mapping.findForward(SUCCESS); }}
    • How do we change Locales? Link to change Struts 1 locale  Calls Action to change Locale<li><html:link action="/Locale?language=es">Español</html:link></li>
    • How do we change Locales? Link to change Struts 2 locale  No Action needed<li> <s:url id="es" action="Hello"> <s:param name="request_locale">es</s:param> </s:url> <s:a href="%{es}">Español</s:a></li>
    • Lets code it!
    • How do we change Locales?Pass "request_locale=es" as parameter1) "es" can be any standard locale code.2) Framework updates locale for session.
    • How do we change Locales?Pass "request_locale=es" as parameter1) "es" can be any standard locale code.2) Framework updates locale for session.
    • How do we change Locales?Pass "request_locale=es" as parameter1) "es" can be any standard locale code.2) Framework updates locale for session.
    • Struts University Series
    • How do we change Locales?(A) <li><html:link action="/Locale?language=es">Español </html:link></li>(B) <li><s:url id="es" action="Hello"> <s:param name="request_locale">es</s:param> </s:url><s:a href="%{es}">Español</s:a> </li>The Struts 1 statement is shown as (A) / (B).The Struts 2 statement is shown as (A) / (B).
    • How do we change Locales?(A) <li><html:link action="/Locale?language=es">Español </html:link></li>(B) <li><s:url id="es" action="Hello"> <s:param name="request_locale">es</s:param> </s:url><s:a href="%{es}">Español</s:a> </li>The Struts 1 statement is shown as (A) / (B).The Struts 2 statement is shown as (A) / (B).
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorSimilar but differentLets compare configurations
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorSimilar but differentLets compare configurations
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorSimilar but differentLets compare configurations
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorSimilar but differentLets compare configurations
    • <?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN""http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd"><form-validation> <formset> <form name="HelloForm"> <field property="message" depends="required"> <arg key="message"/> </field> </form> </formset></form-validation>
    • <?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators> <field name="message"> <field-validator type="requiredstring"> <message key="requiredstring"/> </field-validator> </field></validators>
    • Does Struts 2 use Commons Validator?Struts 1 We validate data on input Add input form to set message  Rather than Action
    • Does Struts 2 use Commons Validator?Struts 1 We validate data on input Add input form to set message  Rather than Action
    • Does Struts 2 use Commons Validator?Struts 1 We validate data on input Add input form to set message  Rather than Action
    • Does Struts 2 use Commons Validator?Struts 1 We validate data on input Add input form to set message  Rather than Action
    • <!-- ... --> <action-mappings> <action path="/HelloInput" name="HelloForm" forward="/HelloInput.jsp" validate="false" /> <action path="/Hello" name="HelloForm" forward="/HelloPage.jsp" validate="true" input="/HelloInput.do" /> </action-mappings></struts-config>
    • <html:errors/><html:form action="/Hello" focus="message" onsubmit="return validateRegistrationForm(this);"><table> <tr><td> Message: </td><td> <html:text property="message" /> </td></tr></table></html:form>
    • Does Struts 2 use Commons Validator?Struts 2 Can reuse the same mapping Input represented by an alternate method Methods can be called via wildcards
    • Does Struts 2 use Commons Validator?Struts 2 Can reuse the same mapping Input represented by an alternate method Methods can be called via wildcards
    • Does Struts 2 use Commons Validator?Struts 2 Can reuse the same mapping Input represented by an alternate method Methods can be called via wildcards
    • Does Struts 2 use Commons Validator?Struts 2 Can reuse the same mapping Input represented by an alternate method Methods can be called via wildcards
    • <action name="Hello!*" method="{1}" class="actions.Hello"> <result>/Hello.jsp</result> <result name="input">/Hello!input.jsp</result></action><s:actionerrors/><s:form action="Hello"> <s:textfield label="Message" name="message"/></s:form>
    • <action name="Hello!*" method="{1}" class="actions.Hello"> <result>/Hello.jsp</result> <result name="input">/Hello!input.jsp</result></action><s:actionerrors/><s:form action="Hello"> <s:textfield label="Message" name="message"/></s:form>
    • Does Struts 2 use Commons Validator?Struts 1 has wildcards tooStill need to set validate=false on inputS2 input method returns “input” symbolS2 validation skipped on input methodInput form posts back to execute (or save, or store, or submit)
    • Does Struts 2 use Commons Validator?Struts 1 has wildcards tooStill need to set validate=false on inputS2 input method returns “input” symbolS2 validation skipped on input methodInput form posts back to execute (or save, or store, or submit)
    • Does Struts 2 use Commons Validator?Struts 1 has wildcards tooStill need to set validate=false on inputS2 input method returns “input” symbolS2 validation skipped on input methodInput form posts back to execute (or save, or store, or submit)
    • Does Struts 2 use Commons Validator?Struts 1 has wildcards tooStill need to set validate=false on inputS2 input method returns “input” symbolS2 validation skipped on input methodInput form posts back to execute (or save, or store, or submit)
    • Does Struts 2 use Commons Validator?Struts 1 has wildcards tooStill need to set validate=false on inputS2 input method returns “input” symbolS2 validation skipped on input methodInput form posts back to execute (or save, or store, or submit)
    • Does Struts 2 use Commons Validator?Struts 1 has wildcards tooStill need to set validate=false on inputS2 input method returns “input” symbolS2 validation skipped on input methodInput form posts back to execute (or save, or store, or submit)
    • resources.propertiesprompt = Enter Messagemessage = Hello World!# Struts 1errors.required={0} is required.# Struts 2requiredstring = ${getText(fieldName)} is required.resources_es.propertiesprompt = Entre el mensajemessage = ¡Hola Mundo!# Struts 1errors.required={0} se requiere.# Struts 2requiredstring = ${getText(fieldName)} se requiere.
    • Lets code it!
    • Does Struts 2 use Commons Validator?Struts 1: numeric parameter errors.required= {0} is requiredStruts 2: expression language requiredstring= ${getText(fieldName)} is required.
    • Does Struts 2 use Commons Validator?Struts 1: numeric parameter errors.required= {0} is requiredStruts 2: expression language requiredstring= ${getText(fieldName)} is required.
    • Struts University Series
    • Does Struts 2 use Commons Validator?Struts 2 uses X**** ValidatorS2 validation skipped on ***** method
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorS2 validation skipped on ***** method
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorS2 validation skipped on input method
    • Does Struts 2 use Commons Validator?Struts 2 uses XWork ValidatorS2 validation skipped on input method
    • Does Struts 2 use Commons Validator?(A) errors.required = {0} is required(B) requiredstring = ${getText(fieldName)} is required.The Struts 1 statement is shown as (A) / (B).The Struts 2 statement is shown as (A) / (B).
    • Does Struts 2 use Commons Validator?(A) errors.required = {0} is required(B) requiredstring = ${getText(fieldName)} is required.The Struts 1 statement is shown as (A) / (B).The Struts 2 statement is shown as (A) / (B).
    • Is that all there is?Cover the basics mappings, Actions, tags, localization, and validation.Converted Hello World to Struts 2 Moved one at a time Actions, pages, and configuration elements Shared essential resources, like message bundles, between the versions.
    • Is that all there is?Cover the basics mappings, Actions, tags, localization, and validation.Converted Hello World to Struts 2 Moved one at a time Actions, pages, and configuration elements Shared essential resources, like message bundles, between the versions.
    • Is that all there is?Cover the basics mappings, Actions, tags, localization, and validation.Converted Hello World to Struts 2 Moved one at a time Actions, pages, and configuration elements Shared essential resources, like message bundles, between the versions.
    • Is that all there is? Struts 2 is a giant leap forward, but, for Struts 1 developers, its a learning curve we can walk, one step at a time.
    • Struts University Series
    • Struts University Series
    • Struts University Series