Creating the Action class
Once configuration is completed, Action(s) can be created and deployed in one of the packages specified in the init param action.packages.
The Action must implement the interface JavajaxAction, which has two methods to be implemented:
public RequestContext getContext();
public void setContext(RequestContext context);
These methods are needed by JavAjax to pass the RequestContext object to the Action, which should be stored in an Action variable for later use.
- @UrlBinding annotation
This annotation can be used at class level to indicate the URL binding this Action should answer to.
i.e.: the action "mypackage.actions.MyAction" would answer, by default, to the url /MyAction.myMethod.page|ajax. This annotation will change this binding with the value specified:
@UrlBinding("Demo")
now the action will answer to the url "/Demo.myMethod.page|ajax"
- Action Method specification
- Method signature
Any method you want to be callable MUST have the "protected" modifier: since the Action is passed to the Jsp, this protection ensures that the method is not called directly from the Jsp, but it is invoked throw a browser call, following framework flow. A typical method would look like:
protected Response myMethod(...) {
...
}
- @DefaultMethod annotation: Action methods are called with the syntax Class|Binding.methodName.page|ajax. The @DefaultMethod annotation specifies which method is invoked when the url does not contain information about the method, i.e. MyAction.page|ajax.
- @OnError annotation: specifies which resource should be called when an error occurs during a page call. If not specified, default error page is called (see error.page in Filter configuration).
- @UrlBinding annotation: specifies the URL binding of this method.
- Method signature
@UrlBinding("UserManager")
public class UserAction implements JavajaxAction {
RequestContext context = null;
public RequestContext getContext() {
return this.context;
}
public void setContext(RequestContext context) {
this.context = context;
}
@DefaultMethod
@UrlBinding("home")
protected Response browseToHome() {
...
return new ForwardResponse("index.jsp");
}
@ParameterMapping(
params={@Param(value="user" mandatory=true)}
)
@OnError("userEdit.jsp")
protected Response editUser(String userId) {
...
return new ForwardResponse("userEdit.jsp");
}
}