J F W

making web application programming easier is possible

HOW TO : WEBAPP

struts.xml

In our example of struts.xml we include two configuration files:

The jfwdefaults.xml contains the configuration of the framework:

The jfwexamples.xml contains the configuration of the action examples:


ActionForm

In Struts 2.x we don't have to declare the classes to use for saving the request parameters.


Action aka *.action

The Action is the equivalent of the Servlet. Every action contains the logic to elaborate a request.
An action can implement the method that returns the instance of the class to use for saving the request parameters (ActionForm), but we don't have to declare the class type in the configuration file.
Every action can be connected with one input jsp or another action. The input jsp (or action) is the one that will be called if validation fails.
An action can have more than one jsps or actions of exit.
Here is an example of an action configuration:

In the previous example we have declared:
  1. name="home_submit" : the url of the action. This is the last part of the url, without the suffix ".action". In our example, the complete path is something like this:
    "http://localhost:8084/jfw-struts2/home_submit.action".
  2. class="com.jfw.example.struts2.action.HomeSubmitAction" : this is the action class.
  3. <result name="input" type="tiles">home</result> : the page to show if the validation fails. Note the use of property type: in this case, we define that the value of the tag is the definition name of a page in tiles2-defs.xml.
  4. <result name="success2">/index.html</result> : One of the possible output pages. Differently from the previous example, the value is the path and the name of a physical page.
There are more details on the execution of the action in the session "HOW TO : CORE".


Resources

We don't have to declare the resource files at project level. For using the keys of a particular resource file, we have to declare it directly in the tag used in jsp:

By default, the keys are searched in a properties file with the name of the action called. In our examples, since all actions extend the class ProjectAction we have set all the common messages in file ProjectAction.properties in package com.jfw.example.struts2.action.


Validator

We don't have to declare the resource files at project level. There is one validator file for action. In our example, we have the file HomeSubmitAction-validation.xml in package com.jfw.example.struts2.action.


Tiles 2.x

The configuration of tiles:

The previous code is in file jfwdefaults.xml.