making web application programming easier is possible


A simple action

An action is basically a Java class (that extends ProjectAction) that receives and manages HTTP requests and redirects the control flow to another resource.We will show an example of an action that just redirects the user to another page.
First of all, the server has to know when the user clicks a link or submits a form, what is the corresponding action to invoke. This information is stored in the jfwexamples.xml file, more precisely in the action element:

In the example above, we have mapped an action, the attribute name declares where the resource is located inside the server, the attribute class indicates the Java class (with fully qualified name) associated with the resource. Below we can see an implemented action that does nothing.

Now we have to decide what the possible results are of the action. As mentioned before, we are just redirecting the user to another page, so that will be the only result possible. And this result has to be declared in the struts-config.xml file as a result element, child of the associated action. That said, our declaration of the action will be changed as follows.

The name attribute of the just added forward element is the logical name we will use in the action. The value of the tag is a resource held by the server and target of the forwarding if the result matches the name attribute. In our case, the target of the forwarding is a tiles definition but it could also be a physical page or another action.
What is left to do now is to implement in the action class, the method myExecute, to return an adequate string to actually forward the user to the page declared into the result element. The modified class is shown below.

In the above code we can see how an action actually uses a forward element "calling" it by its name attribute. In this way any number of forward elements can be declared and called based on the result of the action. In this case the result is just forwarding the user to a page defined in tiles configuration file.