Dear All,
I'm using XDoclet while developing for a project that uses Spring and Struts together. I've found a small problem with this configuration in the way that the Struts-Spring plugin ( http://struts.sourceforge.net/struts-spring/ - although now part of the main spring distribution) operates. I haven't found anything mentioning this on the user or dev archives, so am posting my problem and solution to you all here .... apologies if this is inappropriate.
When I create my Struts action class (say com.cygnite.test.struts.TestAction), which has properties configured through Spring, the entry I need in my struts-config.xml is:
<!-- Note the type attribute is NOT the name of my class -->
<action path="/testAction" type="org.springframework.web.struts.DelegatingActionProxy">
.
.
</action>
while in the Spring configuration file, I need:
<!-- Note that I have a name attribute, and no ID attribute -->
<bean name="/testAction" class="com.cygnite.test.struts.TestAction">
<!-- Example property -->
<property name="dataSource"><ref bean="applicationDataSource"/></property>
</bean>
The 2 problems are:
1. XDoclet's struts module doesn't let you override the "type" attribute for the action, allowing you to specify a different class to instantiate for the action.
2. The spring module doesn't support the "name" attribute, and always specifies an ID attribute - I'm not absolutely sure whether it's ok or not to have the ID attribute there as well, although it might be cleaner and clearer if it wasn't there in this situation.
Both problems are easily fixed by making small changes to the .xdt files for each module. I don't know how you like patches to be applied, so I'm explaining the differences here. If appropriate, could someone point me in the right direction on how to make patch files for the project?
1. In the <xdoclet-struts module>/xdoclet/modules/apache/struts/resources/struts_config_xml.xdt file:
<action
path="<XDtClass:classTagValue tagName="struts:action" paramName="path"/>"
type="<XDtClass:fullClassName/>"
becomes:
<action
path="<XDtClass:classTagValue tagName="struts:action" paramName="path"/>"
<XDtClass:ifHasClassTag tagName="struts:action" paramName="type">
type="<XDtClass:classTagValue tagName="struts:action" paramName="type"/>"
</XDtClass:ifHasClassTag>
<XDtClass:ifDoesntHaveClassTag tagName="struts:action" paramName="type">
type="<XDtClass:fullClassName/>"
</XDtClass:ifDoesntHaveClassTag>
adding the type parameter to the struts.action tag override the standard behaviour of taking the full class name, which still remains the default if no type attribute is specified.
2. Adding to the xtags.xml file for the struts module, inside the struts.action tag definition:
<parameter type="text">
<name>type</name>
<usage-description>
The class to instantiate for this action. Defaults to the current class, but can
be overridden for certain uses, such as integration with Spring.
</usage-description>
<mandatory>false</mandatory>
</parameter>
3. In the <xdoclet-spring module>/
Replacing:
<bean
id="<XDtClass:classTagValue tagName="spring.bean" paramName="id"/>"
with:
<bean
<XDtClass:ifHasClassTag tagName="spring.bean" paramName="id">
id="<XDtClass:classTagValue tagName="spring.bean" paramName="id"/>"
</XDtClass:ifHasClassTag>
<XDtClass:ifHasClassTag tagName="spring.bean" paramName="name">
name="<XDtClass:classTagValue tagName="spring.bean" paramName="name"/>"
</XDtClass:ifHasClassTag>
whch makes the "id" and "name" parameters optional (I couldn't see a way to make a conditional validation to make sure at least one of them was present)
4. Adding to the xtags.xml file for the spring module, inside the spring.bean tag definition (the definition for the ID attribute wasn't present in the xtags file for some reason):
<parameter type="text">
<name>id</name>
<usage-description>
ID for the bean. This should be unique within the spring configuration. Either this
property, or the "name" property must be specified for each bean.
</usage-description>
<mandatory>false</mandatory>
</parameter>
<parameter type="text">
<name>name</name>
<usage-description>
Name for the bean. This property can be used in place of the "id" attribute, where
the name being used contains characters that would be invalid as an XML ID attribute.
</usage-description>
<mandatory>false</mandatory>
</parameter>
This certainly provides me with a solution, although there are a few enhancements to be made (in particular creating the validation of at least one of the ID or name attributes being present in the spring.bean tag). I hope this is an acceptable solution for the rest of the community?
Steve.
- Re: [Xdoclet-devel] Configuring Struts and Spring together ... steve . storey
- Re: [Xdoclet-devel] Configuring Struts and Spring toge... Matt Raible
- Re: [Xdoclet-devel] Configuring Struts and Spring ... steve . storey
