making web application programming easier is possible



Configuring struts using the struts-config.xml file could be complicated, the first time. Let's see the one we can find in the example.

ActionForm aka form-bean

There is a class of this type for every html form. To be precise, the same Actionform could be used for various HTML pages if the form (this is the html tag) contains the same fields. The ActionForm is as simple as a javabean. There are also some methods that allow to carry out the validation of the fields but since in JFW the Struts Validator is used, we can forget these methods.
Here is an example of a form bean configuration:

In the example above, a form bean that manages the authentication of the USER has been configured. The tag type must be the name of an existing class and the tag name is the logical name of the form bean. This name will be used in the configuration of Actions.

Action aka *.do

The Action is the equivalent of the Servlet.
Every action contains the logic for elaborating a request.
An action could be connected with one form bean.
Also, 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. path="/home_submit" : the url of the action. This is the last part of the url, without the suffix ".do". In our example, the complete path is something like this:
  2. type="com.jfw.example.struts.action.HomeSubmitAction" : this is the action class.
  3. name="home_form" : the form bean used by the action.
  4. input="/jsp/project/home_tile.jsp" : the page to show if the validation fails.
  5. validate="true" : before the execution of the action, the parameters sent from the browser will be validated. If the validation fails, the previous jsp (or an action or an html page) with the validation error messages will be displayed.
  6. scope="request" : the form bean will be available until the validation phase and the execution of the action are done.
  7. forward name="success" path="/jsp/project/home_submit_tile.jsp": this is one possible page that shows when the execution of the action is finished.
There are more details on the execution of the action in the session "HOW TO : CORE".


The resources are properties files containing the messages to be shown in the jsps. The use of the resources allows us to visualize the messages in more languages and to add new languages without modifying the jsps. In our example we use the resources to declare the text of the jsps and the error messages.
Here is the configuration of the main (default) resource:

and this is an example of how to declare another resource:

The "key" attribute is the logical name of the resource and is the one to use when we want to visualize a message from a particular resource. By default, the messages are got from the default resource file (the "ApplicationResources" in our example).

There are more details on the use of the resources in the session "HOW TO : WEBAPP > validation.xml" and in "HOW TO : CORE".


The configuration of the validator:


The configuration of tiles: