Transcription of Migrating from Struts 1 to Struts 2 - Software Summit
1 Migrating from Struts 1 to Struts 2 Matt RaibleVirtuas Open Source Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 1 Introductions Your experience with Java? Your experience with Web Frameworks? What do you hope to learn today? Open Source experience: Ant, Struts , WebWork, Spring, Hibernate, Eclipse, To m c a t ? Favorite IDE? Favorite OS? Favorite Server?Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 2 Matt Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 3 RaibleColorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 4 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 5 Colorado Software Summit .
2 October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 6 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 7 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 8 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 9 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 10 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 11 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 12 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 13 Colorado Software Summit .
3 October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 14 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 15 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 16 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 17 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 18 Web Framework Experience Struts : used since June 2001 - same time was released.
4 Spring MVC: used since January 2004 - before was released. WebWork: used since July 2004. Tapestry: used since July 2004. JSF: used since July 2004 - both Sun s RI and Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page for from Struts 1 to Struts from WebWork 2 to Struts and AColorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 20 Struts OverviewColorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 21 Struts Pros.
5 The Standard - lots of Struts jobs Lots of information and examples HTML tag library is one of the best Cons: ActionForms - they re a pain Can t unit test - StrutsTestCase only does integration Project has been rumored as dead Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 22 Struts Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 23 Struts LifecycleColorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 24 Struts Actionpublic class UserAction extends DispatchAction { private UserManager mgr = null; public void setUserManager(UserManager userManager) { = userManager; } public ActionForward delete(ActionMapping mapping, ActionForm form , HttpServletRequest request, HttpServletResponse response) throws Exception { DynaActionForm userForm = (DynaActionForm) form ; User user = (User) ("user"); ( (" ")); ActionMessages messages = new ActionMessages().}}
6 ( , new ActionMessage(" ", ())); saveMessages( (), messages); return ("users"); }Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 25 Struts Actionpublic class UserAction extends DispatchAction { private UserManager mgr = null; public void setUserManager(UserManager userManager) { = userManager; } public ActionForward delete(ActionMapping mapping, ActionForm form , HttpServletRequest request, HttpServletResponse response) throws Exception { DynaActionForm userForm = (DynaActionForm) form ; User user = (User) ("user"); ( (" ")); ActionMessages messages = new ActionMessages(); ( , new ActionMessage(" ", ())); saveMessages( (), messages); return ("users").}
7 }Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 26 Struts Actionpublic class UserAction extends DispatchAction { private UserManager mgr = null; public void setUserManager(UserManager userManager) { = userManager; } public ActionForward delete(ActionMapping mapping, ActionForm form , HttpServletRequest request, HttpServletResponse response) throws Exception { DynaActionForm userForm = (DynaActionForm) form ; User user = (User) ("user"); ( (" ")); ActionMessages messages = new ActionMessages(); ( , new ActionMessage(" ", ())); saveMessages( (), messages); return ("users").}
8 }Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page < form -bean name="userForm" type=" "> < form -property name="user" type=" "/> </ form -bean> <action path="/user" type=" " name="userForm" scope="request" parameter="method" validate="false"> <forward name="list" path=" "/> <forward name="edit" path=" "/> </action> <plug-in className=" "> <set-property property="contextConfigLocation" value="/WEB- "/> </plug-in>Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 28 Display Tag<display:table name="users" class="list" requestURI="" id="userList" export="true"> <display:column property="id" sort="true" href=" " paramId="id" paramProperty="id" titleKey=" "/> <display:column property="firstName" sort="true" titleKey=" "/> <display:column property="lastName" sort="true" titleKey=" "/> <display:column titleKey=" " sort="true" sortProperty="birthday"> <fmt:formatDate value="${ }" pattern="${datePattern}"/> </display:column> </display:table>Colorado Software Summit .
9 October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 29 Struts : JSP View<html: form action="/user" focus=" " onsubmit="return validateUserForm(this)"> <input type="hidden" name="method" value="save"/> <html:hidden property=" "/> <table class="detail"> <tr> <th> <label for=" "> <fmt:message key=" "/>:</label> </th> <td> <html:text property=" " styleId=" "/> </td> </tr> <tr> <th> <label for=" "> <fmt:message key=" "/>:</label> </th> <td> <html:text property=" " styleId=" "/> <span class="fieldError"> <html:errors property=" "/> </span> </td> </tr> <th> <label for=" "> <fmt:message key=" "/>:</label> </th> <td> <c:set var="datePattern"> <fmt:message key=" "/> </c:set> <input type="text" size="11" name=" " id=" " value="<fmt:formatDate value="${ }" pattern="${datePattern}"/>"/> [${datePattern}] </td> <tr>Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 30 Struts : JSP View<html: form action="/user" focus=" " onsubmit="return validateUserForm(this)"> <input type="hidden" name="method" value="save"/> <html:hidden property=" "/> <table class="detail"> <tr> <th> <label for=" "> <fmt:message key=" "/>:</label> </th> <td> <html.
10 Text property=" " styleId=" "/> </td> </tr> <tr> <th> <label for=" "> <fmt:message key=" "/>:</label> </th> <td> <html:text property=" " styleId=" "/> <span class="fieldError"> <html:errors property=" "/> </span> </td> </tr> <th> <label for=" "> <fmt:message key=" "/>:</label> </th> <td> <c:set var="datePattern"> <fmt:message key=" "/> </c:set> <input type="text" size="11" name=" " id=" " value="<fmt:formatDate value="${ }" pattern="${datePattern}"/>"/> [${datePattern}] </td> <tr>Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 31 WebWork / Struts 2 Colorado Software Summit : October 22 27, 2006 Copyright 2006, Virtuas Open Source SolutionsMatt Raible Migrating from Struts 1 to Struts 2 Page 32 WebWork / Struts 2 Pros: Simple architecture - easy to extend Tag Library is easy to customize with FreeMarker or Velocity Interceptors are pretty slick Controller-based or page-based navigation Cons: Small Community