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

Compare with Current View Page History

« Previous Version 4 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

Here are some notes on the series of steps that you might run through to migrate an existing Roller struts1 action to a new struts2 action. The specific details of the work will vary depending on the situation.

  • 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(). access to the authenticated UserData object is provide for you by having your action extend the UIAction class, so there is nothing that you need to do. by default, all actions require an authenticated user, so if the user is not properly authenticated when trying to access an action then they will get an access denied page.
    • remove all attempts to get the weblog used by the action via a RollerRequest object and replace with a simple call to getActionWeblog(). just like above, this is extracted from the request and populated for you.
    • to see how you can control the security options for your action, check out the UISecurityEnforced interface which provides control points. this interface is implemented by the UIAction class which you most likely should be extending, so you can modify the default behavior by simply overriding any of the methods from that interface in your action class.
  • fix action method declarations to
    • return just a String
    • not accept any params
    • not throw any exceptions (handle these inside your action method!)
  • 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