Managing struts-config.xml


When the development begins, the struts-config.xml is always small and manageable. But as time passes and features are added, the file continues to grow to become a monster. Splitting the application into modules definitely helps, but modules can be relatively large too. There are better ways to mange the struts-config.xml than simply editing by hand or even an XML editor. Some of the popular tools to manage struts-config.xml are described below.

Struts-GUI

Struts-GUI is a Visio Stencil from Alien Factory (http://www.alienfactory.co.uk/strutsgui/). It lets you visually edit the struts config.xml as a Visio diagram and generate the xml file from it. One of the biggest challenges in maintaining the struts-config.xml is understanding the flow and tracking down what is going on. With Struts-GUI, you can follow the visually trace the actions, their forwards and the web pages they lead to. You can even trace action chaining. You can add documentation in the Visio diagram reducing the maintenance hurdle even further. Struts-GUI is a commercial tool.

Struts Console

Struts Console is a Swing based editor to manage the struts-config.xml from James Holmes (http://www.jamesholmes.com/struts/console/). It is not visually driven as Struts GUI, but very intuitive. It has tree like navigation to traverse the individual elements. It is much more flexible than Struts GUI in that it can be used to maintain customized struts-config.xml (More about Struts customization in Chapter 10). Wizards and drop downs are provided to add inidividual elements, thus eliminating the chances of typo.

XDoclet

XDoclet based management of struts-config.xml is a entirely different concept. The two tools cited earlier are based on maintaining the struts-config.xml , while in XDoclet approach, there is no struts-config.xml at all! In the XDoclet approach, there is no struts-config.xml at all! All the requisite information linked to the < form-bean > and < action > are specified in the Action and Form classes using special XDoclet tags as follows :

 * @struts.action name="custForm" path="/editCustomer"  *                scope="request" validate="false"  *                parameter="action" input="mainpage" * * @struts.action-forward name="showCustForm"  *                        path="/ShowCustomerForm.jsp" 

The above tags generate the Struts action mapping as follows in the struts-config.xml at build time.

 <action path="/editCustomer"               type="mybank.app1.ShowCustomerAction"              name="custForm"               scope="request"               input="mainpage"               unknown="false" validate="false">         <forward name="showCustForm"                   path="/ShowCustomerForm.jsp"                   redirect="false"/>     </action> 

XDoclet is project on sourceforge that started off with auto-generating home interface, remote interface, ejb-jar.xml from special tags in the EJB implementation class. It was a good idea with EJBs since the EJB implementation class would drive everything else - home, remote and the ejb-jar.xml .

With struts-config.xml , none of the individual classes drive the flow in entirety. Everything works always in relation to another. You always want to track what is going on, how various pieces interact together and how the flow works. You always want to see which action takes you where and get the whole big picture as you develop. Hence the struts-config.xml serves much like whiteboarding - visualizing whats going on in its entirety. Providing this information via piecemeal approach in different files using XDoclet tags defeats the purpose. Providing this information via piecemeal approach in different files using XDoclet tags defeats the purpose. Hence our advice is not to use the XDoclet approach for auto-generating struts-config.xml .




Struts Survival Guide. Basics to Best Practices
Struts Survival Guide: Basics to Best Practices (J2ee Survival Series)
ISBN: 0974848808
EAN: 2147483647
Year: 2004
Pages: 96

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