Apache Struts 2 Documentation > Home > Guides > Migration Guide > Issues and Solutions |
This page is meant to be a list of issues that users ave encountered while migrations existing Struts 1 application to Struts 2, or developing new Webwork-based applications. If you have a solution to the issue that will of course be most helpful, but even if you don't it is worth noting what you encountered none the less in the hopes that someone else can come along and answer it for you, and the rest of us.
If the Action is model-backed and persisted in the session
See also
SAF1 generates a little JavaScript that helps set the focus, if you specify the field in the JSP.
Another solution is to use a generic Javascript that automatically seeks the first enabled form field on page.
(Building this script into Struts 2 is being considered.)
The default Action class (ActionSupport) returns SUCCESS by default, and SUCCESS is the default result. Using an action to forward directly to a page is easy:
<action name="Welcome">
<result>/pages/Welcome.jsp</result>
</action>
Rather than tag the action as being the default, the default action is set by name using default-action-ref element.
<default-action-ref name="defaultAction">
By using an element, rather than an attribute, packages can inherit the default action name.
Starting in Struts 1.3, you could use the "extends" attribute in your Struts configuration Action mapping to have it inherit properties from a base mapping. In Struts 2, that technique is no longer necessary because you have packages. You can create a package, then set for that package the default Result type, Interceptor chain, and global results. This leaves very little information to actually be included in an action element.
Here is an example of declaring a custom package:
<package name="chat" extends="struts-default" namespace="/chat"> <global-results> <result name="login" type="freemarker">/chat/chatLogin.ftl</result> </global-results> <default-interceptor-ref name="basicStack"/> ... </package>
In fact, packages themselves can extend other packages, as the "chat" package extends "struts-default" in the above example.
DynaBeans can be treated as a regular Java object, if the particular implementation contains a getMap() method. This method lets OGNL, the Struts 2 expression language, know how to access and set data. DynaBean variants like the LazyDynaBean can create themselves on-the-fly, where other more static types might need to be created in your Action's constructor before being used. However, one of the benefits of Struts 2 over Struts 1.x is that you can use your existing JavaBeans directly without the need of an ActionForm-type wrapper, so you might try bypassing the familiar DynaBean route.
This material originally adopted from: http://wiki.apache.org/struts/IssuesAndSolutions.