I'm submitting the transformations package as a struts extension. I've also updated the extensions package to include support for the destroy() and initDigester() functions and repackaged the source/class files into a .zip file (thanks Niall, Ted). What's a transformation? Briefly: Transformations are responsible for taking an object in one form and transforming it into another. Specifically, they can be used for transforming properties of business objects for inclusion in a JSP page, and processing fields received in the HTTP request. Note that this transformation package depends on the extensions package I sent out a couple days ago. Both packages, along with design docs & samples, can be retrieved from: http://www.rpsenterprises.com/struts/ The README for transformations has more information and is attached to this file. Enjoy.
Transformations Package This package contains the transformations functionality for the struts framework. This package is a type of struts extension, so this package is dependent on the extensions package (http://www.rpsenterprises.com/struts/). You'll have to include that .jar file and use the ExtensionServlet. Transformations are responsible for taking an object in one form and transforming it into another. Specifically, transforming properties of business objects for inclusion in a JSP page, and processing fields received in the HTTP request. The Transformation base class has a concept of a forward transformation, and reverse transformation. A forward transformation takes an object from its primary form to a secondary form (e.g. Date object to String). A reverse transformation takes an object from a secondary form to its primary form (e.g. String to Date). Transformations are created by a transformations factory (TransFactory). The SimpleTransFactory, which implements the TransFactory interface, returns transformations that were configured from an XML configuration file. The transformations configuration file lists the transformations that are to be created and returned by the factory. The format is pretty straightforward: <transformations> <transformation className="org.strutsx.transformations.SimpleSortTrans" name="simpleSort" makeCopy="true"> </transformation> </transformations> In the above example, a single transformation is being configured. The class of the transformation is identified by the className attribute. Every transformation must have className & name attributes. The name is used to look up the transformation. Any other attributes are specific to the transformation being configured. In the above example, makeCopy is being set to true, specifying the sorting transformation should make a copy of the collection being sorted. See testTransformations.xml for an example. I've subclassed a couple struts JSP tags to make them transformation-aware. They are the bean:write and logic:iterate tags. I call them beanx:write and logicx:iterate. Both tags now take a transformation argument which is a reference to the transformation object to be applied. The iterate tag also takes a transArg1 argument which gets passed to the Transformation object. Specifically, I've been using transArg1 to pass the sort order (ascending/descending) to the sort transformation. See testTrans.jsp for an example. As I said above, transformations depends on the extensions package. To set up the transformations extensions, you must insert something like the following into your struts-config.xml: <struts-config> ... ... <extensions> <extension className="org.strutsx.transformations.TransformationsExtension" configRes="/WEB-INF/testTransformations.xml"> </extension> </extensions> ... ... The configRes argument tells TransformationsExtension where to find its configuration file. Can't think of much more than that at the moment. If you're interested, take a look at the sample JSP file, config file, and the design/JavaDocs. And as always, let me know if you find the package useful or have suggestions. --Ron S. ([EMAIL PROTECTED])