Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
  • 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?

One of the Struts "best practices" is that all requests within an application should go through Struts. So, you should generally never reference a JSP directly for instance. To help with this, Struts provides the !ForwardAction, which is more or less an Action that does nothing, it just immediately returns and forwards to the URI as configured. Webwork does not appear to have a direct analogy to this. However, it is easy to get the same effect in a couple of possible ways.

First, you can write a simple Action like so:

Code Block

package com.company.app;

import com.opensymphony.xwork.Action;

public class ForwardAction implements Action {

  public String execute() {
    return SUCCESS;
  }

}

Then, configure an Action like this:

Code Block

<action name="justAForward" class="com.company.app.ForwardAction">
  <result name="success">pageToDisplay.jsp</result>
</action>

Now you can use that !ForwardAction whenever you like, just as you would in Struts. Alternatively, if you don't want to have a whole Action just for that, you can simply have a method in an existing Action (named something other than execute, let's say "gotoJSP" for the sake of argument) and configure an Action like so:

Code Block

<action name="justAForward" class="com.company.app.SomeExistingAction" method="gotoJSP">
  <result name="success">pageToDisplay.jsp</result>
</action>

An even easier solution however, as suggested by Ted Husted in the thread referenced below, is to use the !ActionSupport class. Your mapping then is just:

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:

Code Block

<action name="Welcome">
<result>/pages/Welcome.
Code Block

<action name="justAForward" class="com.opensymphony.xwork.ActionSupport">
  <result name="success">pageToDisplay.jsp</result>
</action>

Because the default implementation of execute() in !ActionSupport simply returns SUCCESS, and since execute() is called by default when no method is specified in the mapping, this does exactly the same thing as the Action code shown above, without the need for a custom class being introduced.

Here is a reference to the thread discussing this: http://forums.opensymphony.com/thread.jspa?threadID=23755&tstart=15

How do you emulate the default="true" attribute of a SAF1 Action mapping?

In SAF1, it is possible to set the default attribute of an Action mapping in struts-config.xml to true.  Then, any request coming in to ActionServlet that does not match a configured Action mapping will result in that mapping being executed.

SAF2 does not (at this point in time at least) provide this attribute.  However, there is a way to get the same effect.

Within xwork.xml (struts.xml?), on a per-package basis, you can have the following: Rather than tag the action as being the default, the default action is set by name using default-action-ref element.

Code Block
<default-action-ref name="defaultAction">

 This says that for the package this is declared in, the mapping with the name defaultAction will be executed when any request comes in that does not match any other mappingBy using an element, rather than an attribute, packages can inherit the default action name.

Next: ActionContext

...

This material originally adopted from: http://wiki.apache.org/struts/IssuesAndSolutions.