Adding Actions

 < Day Day Up > 



The <action-mappings> sub-element is used to define n-number of <action> sub-elements. It acts as a container for <action> sub-elements; therefore, this section focuses on the actual configuration of individual <action> sub-elements.

The <action> sub-element is used to describe an Action instance to the ActionServlet. It represents the information that uniquely defines an instance of a particular Action class. The syntax of the <action-mappings> sub-element, including an example <action> sub-element, is:

 <action-mappings>   <action     path="context-relative path mapping action to a request"     type="fully qualified class name of the Action class"     name="the name of the form bean bound to this Action">     <forward name="forwardname1" path="context-relative path"/>     <forward name="forwardname2" path="context-relative path"/>   </action> </action-mappings> 

start sidebar

Notice that the <action> element in the previous code snippet contains two <forward> sub-elements. These sub-elements are defined as the <forward> elements nested inside a <global-forwards> element, except that they are local to the defined <action> sub-element. These <forward> sub-elements can be referenced only by their parent <action>.

end sidebar

Table 15.7 describes the attributes of an <action> sub-element.

Table 15.7: The Attributes of an <action> Sub-Element

Attribute

Description

path

Represents the context-relative path of the submitted request. The path must start with a / character. (required)

type

Specifies the fully qualified class name of the Action class being described by this ActionMapping. The type attribute is valid only if no include or forward attribute is specified. (optional)

name

Identifies the name of the form bean, if any, that is coupled with the Action being defined. (optional)

scope

Specifies the scope of the form bean that is bound to the described Action. The default value is session. (optional)

input

Represents the context-relative path of the input form to which control should be returned if a validation error is encountered. Control is returned to the input attribute if ActionErrors are returned from the ActionForm or Action objects. (optional)

className

Specifies the fully qualified class name of the ActionMapping implementation class you want to use in when invoking this Action class. If the className attribute is not included, then the ActionMapping defined in the ActionServlet's mapping initialization parameter is used. (optional)

forward

Represents the context-relative path of the servlet or JSP resource that will process this request. This attribute is used if you do not want an Action to service the request to this path. The forward attribute is valid only if no include or type attribute is specified. (optional)

include

Represents the context-relative path of the servlet or JSP resource that will process this request. This attribute is used if you do not want an Action to service the request to this path. The include attribute is valid only if no forward or type attribute is specified. (optional)

validate

If set to true, causes the ActionForm.validate() method to be called on the form bean associated to the Action being described. If the validate attribute is set to false, then the ActionForm.validate() method is not called. The default value is true. (optional)

The following code snippet contains an example using the <action-mappings> sub-element:

 <action-mappings>   <action path="/lookupAction"     type="wrox.LookupAction"     name="LookupForm"     scope="request"     validate="true"     input="/index.jsp">     <forward name="success" path="/quote.jsp"/>     <forward name="faliue" path="/index.jsp"/>   </action> </action-mappings> 



 < Day Day Up > 



Professional Jakarta Struts
Professional Jakarta Struts (Programmer to Programmer)
ISBN: 0764544373
EAN: 2147483647
Year: 2003
Pages: 183

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net