This page is meant to be a list of issues that users ave encountered while migrations existing SAF1 application to SAF2, 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.
How do we set checkboxes false (on uncheck)?
- Use a boolean to represent the checkbox property
- Implement the
preparable
interface- Implement a
prepare
method and set all checkbox booleans to false
- Implement a
- Or, set the checkbox booleans to the false value using static parameters.
If the Action is model-backed and persisted in the session
- Use an Action property as a buffer for the checkbox boolean.
- On Save, set the model property to the Action property.
- These extra steps avoid setting the model properties to false prematurely.
See also
How to set the focus on a form field?
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 SAF2 is being considered.)
What is the analogy to ForwardAction?
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>
How do you emulate the default="true" attribute of a Struts 1.x Action mapping?
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.
How do you extend an action mapping in struts.xml??
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.
Can I use DynaBeans in my Struts actions?
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.
Next: What is the ActionContext?
This material originally adopted from: http://wiki.apache.org/struts/IssuesAndSolutions.