You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Roller Struts2 Migration

This page provides info relevant to the Roller struts2 migration effort which is starting as of Roller 4.0 and will end ??

Changes in Design

Migration Notes

Migrating Actions

  • copy old action code to new action class and rename (makes things less confusing)
  • make sure package name is appropriate at the top of your copied code
  • extend UIAction (MigratingUIAction if request object is really needed, but try not to)
  • define security needs of your action.
    • remove all attempts to get authenticated user via RollerSession and replace with a simple call to getAuthenticatedUser();
    • if your action tries to create a RollerSession from a request to access the authenticated user then you need to replace that code with a simple call like "UserData user = getAuthenticatedUser();". this is a nice freebee that has been setup via our struts2 config so that the authenticated user is extracted and made available to you automatically by extending the UIAction class. so you don't need to use RollerSession to access the authetnicated user anymore (smile)
  • fix action method declarations to
    • return just a String
    • not accept any params
    • not throw any exceptions
  • fix action method results to just return a String instead of an ActionForward
  • if your action handles a lot of fields then define a class level attribute called "bean" with getters and setters. if your action only needs to make use of a couple fields then you can just define those attributes directly in your action and provide getters and setters.
    • NOTE: if you are defining a "bean" in your action, make sure that the bean gets initiated. i.e. you can't define your bean as "MyBean bean = null" because that's not an initiated attribute. instead you should probably do this ... "MyBean bean = new MyBean()"
    • once that is done you need to change usages of the old action form.xxx() calls to getBean().xxx() or just xxx() if you didn't define a "bean".
    • now you can delete all old code which trys to extract the form bean from the passed in actionForm
  • fix up error/message handling
    • delete all instances of ActionMessages() and ActionErrors()
    • delete all calls to saveMessages() and saveErrors()
    • replace all attempts to set action messages/errors with calls to addMessage(key), addMessage(key, param), addError(key), and addError(key, param)
  • fix up form validation
    • if there is a custom validate() method then replace it with a no arg method myValidate()
  • tidy up the action results.
    • try to use the defaults like SUCCESS and INPUT, and custom ones where applicable, like "cancel".
  • fix up use of "models"
    • replace all attempts to set a "model" attribute on the request object with a call to setModel()
    • modify all custom "model" objects either just use UIModel or extend UIModel
    • NOTE: you may need to begin the process of migrating the jsps a bit in order to decide how much of the old model class you need to keep. it's entirely possible that once you rework the jsp a bit you'll find that most of the elements of the old model class are no longer needed.

Migrating JSPs

  • replace include for taglibs.jsp to taglibs-struts2.jsp
  • do a search and replace for "fmt:message key" with "s:text name"
  • replace html:form with s:form and delete the method param
  • change the new s:form action attribute to the correct action name, like myAction!method
  • replace instances of "html:text property" with "s:textfield name"
  • add "bean." in front of all name attributes for form fields
  • No labels