5.13.2.2 Struts Configuration File

 



Overview

 

The struts-config.xml configuration file is a link between the View and Model components in the Web Client. It plays an important role in building both Controller components and Application-specific configurations. In Web NMS, this file is created specific to every application in the format as <module>-struts-config.xml, where <module> can be topo, fault, perf and so on. For example, a struts-config.xml file of the fault module is represented as fault-struts-config.xml and is present in <Web NMS Home>/webclient/fault/conf directory.

 

Configuration File Structure

 

The configuration file basically contains three main elements:

The elements of the <module>-struts-config.xml file and their usage are described for an example module such as "fault".

 

Element

Attributes and Description

struts-config

 

Is the root node of the configuration file.

 

form-beans

 

Contains form bean definitions. The Form beans create ActionForm instances at runtime. The details of each form bean are provided in the <form-bean> element. The <form-property> elements within the form bean contain the property names and the property types of the form bean.

 

Attributes of <form-bean> are:

  • name: Must have a unique bean name. This name is used as reference in the action mappings. Often, this is also the  name of the request or the session attribute under which the form is stored.

  • type: The value is a fully-qualified classname of the ActionForm class used with the form bean.

Attributes of <form-property> are:

  • name: Contains the name of a property of the form bean.

  • type: Contains the property type such as String, String[], etc.

Example Entry

 

<form-bean name="EventCVForm" type="org.apache.struts.validator.DynaValidatorForm">

  <form-property name="cvName" type="java.lang.String"/>

  <form-property name="severity" type="java.lang.String[]"/>

  ......

</form-bean>

 

global forwards

Contains the global forward definitions. The forward name is the logical name used to map to a specific JSP. The logical name mappings for commonly used presentation pages are specified here. The <forward> element contains the logical name and the name of the corresponding resource which it maps to.

 

Attributes of <forward> are:

  • name: Contains the logical name of the forward. This name is used in the ActionForm class's execute() method to forward it to the next resource. Example: MyTestPage

  • path: Contains the context relative path of the resource to which the forward name maps. Example: /TestPage.jsp [or] /TestPage.do

  • contextRelative:This takes the value true or false implying, whether the resource specified in the path attribute is relative to the context.

Example Entry

 

<forward name="viewAlarm" path="/fault/AlarmView.do" contextRelative="true"/>

 

In the above entry, wherever this file is to be called, only viewAlarm is specified. This allows you to change the Alarm View page without changing the references to it throughout the Web Client. The action mapping for the AlarmView.do is defined in the action mapping, where it is forwarded to the next appropriate resource.

 

action-mappings

Contains the action definitions. Each action mapping is defined in an <action> element. The <forward> definition within <action>, maps the result of the action to the jsp page invoked. This is a 'local' forward and is optional. That is, for the particular request object, if there is no forward defined in the global forwards, it is specified in the <action-mapping> element.

Attributes of <action-mappings> are:

  • path: Contains the name of the request received

  • type: Contains the name of the action class invoked

  • scope: Specifies the scope in which the Controller (ActionServlet) must look for the bean

Attributes of (local) <forward> within <action-mappings> are the same as that of the global <forward>.

Example Entry

 

<action-mappings>

<action path="/NetworkEvent"

            type="com.adventnet.nms.webclient.fault.event.EventViewAction"

            scope="request">

        <forward name="eventView" path="NetworkEventPage" contextRelative="true"/>

</action>

</action-mappings>

 

In the above entry, when a request matching the specified path (NetworkEvent) is received, an instance of the ActionClass is created. The controller looks for the bean in the specified scope (request) creating and saving a bean of the specified class, if needed. The ActionForward object is returned and the reference to the object is acquired using mapping.findforward .. The layout for the page displaying network events is defined in the corresponding tiles definition file, where the page components and the corresponding JSPs are specified.

 

controller

The <controller> enables you to configure the ActionServlet. In the example entry, the <controller> element defines the <action> elements in Fault to be local or global ActionForward names.
 

The inputForward parameter is set true, meaning the input attribute of the <action> elements is the name of a local or global ActionForward, which will then be used to calculate the end URL. Set it false to treat the input parameter of <action> elements as a module-relative path to the resource to be used as the input form.

 

<controller inputForward="true" />

 

plug-in

The <plug-in> element is used to include plug-ins in struts. The Web Client uses the Tiles plug-in and the Struts Validator plug-in. The following <plug-in> includes the Tiles plug-in in the Fault module.

 

<plug-in className="org.apache.struts.tiles.TilesPlugin" >

<set-property property="definitions-config" value="/webclient/fault/conf/fault-tiles-defn.xml" />

<set-property property="moduleAware"
value="true" />

</plug-in>

 

The nested <set-property> element is used to configure the tiles plug-in to point to the tiles definition file for Fault module. The tile definition is specified in fault-tiles-defn.xml located in /webclient/fault/conf/ directory.

 

<plug-in className="org.apache.struts.
validator.ValidatorPlugIn">

<set-property property="pathnames" value="/webclient/fault/conf/fault-validator-rules.xml,/webclient/fault/conf/fault-validation.xml"/>

</plug-in>

 

The following <plug-in> includes the Struts Validator plug-in in the Fault module

 

 

 


Copyright © 2013, ZOHO Corp. All Rights Reserved.