Migrating from Struts 1 to Struts 2 - Software · PDF fileJSF: used since July 2004 ... Matt...

download Migrating from Struts 1 to Struts 2 - Software · PDF fileJSF: used since July 2004 ... Matt Raible Ñ Migrating from Struts 1 to Struts 2 Page 31. ... log.debug("Cancelling validation,

If you can't read please download the document

Transcript of Migrating from Struts 1 to Struts 2 - Software · PDF fileJSF: used since July 2004 ... Matt...

  • Migrating from Struts 1 to Struts 2

    Matt RaibleVirtuas Open Source Solutions

    [email protected]

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt 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, Tomcat?

    Favorite IDE? Favorite OS? Favorite Server?

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 2

  • Matt

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 3

  • Raible

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 4

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 5

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 6

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 7

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 8

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 9

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 10

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 11

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 12

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 13

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 14

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 15

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 16

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 17

  • Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 18

  • Web Framework Experience

    Struts: used since June 2001 - same time 1.0 was released.

    Spring MVC: used since January 2004 - before 1.0 was released.

    WebWork: used since July 2004.

    Tapestry: used since July 2004.

    JSF: used since July 2004 - both Suns RI and MyFaces.

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 19

  • Agenda

    1.Struts Overview

    2.WebWork Overview

    3.Reasons for Upgrading

    4.Migrating from Struts 1 to Struts 2

    5.Migrating from WebWork 2 to Struts 2

    6.Pitfalls

    7.Q and A

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 20

  • Struts 1.x Overview

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 21

  • Struts 1.x

    Pros:

    The Standard - lots of Struts jobs

    Lots of information and examples

    HTML tag library is one of the best

    Cons:

    ActionForms - theyre a pain

    Cant unit test - StrutsTestCase only does integration

    Project has been rumored as dead

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 22

  • Struts 1.x

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 23

  • Struts 1.x Lifecycle

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt 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) {

    this.mgr = userManager;

    }

    public ActionForward delete(ActionMapping mapping, ActionForm form,

    HttpServletRequest request,

    HttpServletResponse response)

    throws Exception {

    DynaActionForm userForm = (DynaActionForm) form;

    User user = (User) userForm.get("user");

    mgr.removeUser(request.getParameter("user.id"));

    ActionMessages messages = new ActionMessages();

    messages.add(ActionMessages.GLOBAL_MESSAGE,

    new ActionMessage("user.deleted", user.getFullName()));

    saveMessages(request.getSession(), messages);

    return mapping.findForward("users");

    }

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt 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) {

    this.mgr = userManager;

    }

    public ActionForward delete(ActionMapping mapping, ActionForm form,

    HttpServletRequest request,

    HttpServletResponse response)

    throws Exception {

    DynaActionForm userForm = (DynaActionForm) form;

    User user = (User) userForm.get("user");

    mgr.removeUser(request.getParameter("user.id"));

    ActionMessages messages = new ActionMessages();

    messages.add(ActionMessages.GLOBAL_MESSAGE,

    new ActionMessage("user.deleted", user.getFullName()));

    saveMessages(request.getSession(), messages);

    return mapping.findForward("users");

    }

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt 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) {

    this.mgr = userManager;

    }

    public ActionForward delete(ActionMapping mapping, ActionForm form,

    HttpServletRequest request,

    HttpServletResponse response)

    throws Exception {

    DynaActionForm userForm = (DynaActionForm) form;

    User user = (User) userForm.get("user");

    mgr.removeUser(request.getParameter("user.id"));

    ActionMessages messages = new ActionMessages();

    messages.add(ActionMessages.GLOBAL_MESSAGE,

    new ActionMessage("user.deleted", user.getFullName()));

    saveMessages(request.getSession(), messages);

    return mapping.findForward("users");

    }

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 27

  • struts-config.xml

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 28

  • Display Tag

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 29

  • Struts 1.x: JSP View

    :

    :

    : [${datePattern}]

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 30

  • Struts 1.x: JSP View

    :

    :

    : [${datePattern}]

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open Source Solutions

    Matt Raible Migrating from Struts 1 to Struts 2 Page 31

  • WebWork / Struts 2

    Colorado Software Summit: October 22 27, 2006 Copyright 2006, Virtuas Open