Struts 2’s missing configuration tag
Written on January 10, 2008 – 12:00 am | by mpayne
Originally, I was looking for something that allowed me to refer to the package name from using the wildcard syntax.
This would allow me to template out my crud actions using a concise configuration and follow my pattern of development with zero-config/annonations did not.
With that not in place I found hope to solve my problem in a fairly similar fashion.
It involves use of a tag that has not made its way to the dtd.
"default-class-ref"
I am eagerly waiting for this simple tag to finally make its way to the struts2 dtd.
It was originally added to the xwork dtd, but lagged in finally getting it over to struts2.
Despite some resistance by Don Brown, I believe in many circumstances it is even more beneficial than the tag.
One can forgo the wildcard, zero configuration, rest, or xyz plugin and use good ole fashion configuration inheritance.
consider the possibilities with templating out your abstract action, the substituting what class is used –>
<package name="Abstract-crud" extends="struts-default" abstract="true">
<!– edit is often used as the create/view –>
<action name="edit" >
<result name="input" type="velocity">edit.vm</result>
<result name="success" type="velocity">edit.vm</result>
<result name="error" type="velocity">edit.vm</result>
</action>
<action name="save" >
<result name="input" type="velocity">edit.vm</result>
<result name="success" type="chain">list</result>
<result name="error" type="velocity">edit.vm</result>
<result name="cancel" type="redirect">list.action</result>
</action>
<action name="list" method="list">
<result name="success" type="redirectAction">list</result>
</action>
<action name="delete" method="delete">
<result name="success" type="redirectAction">list</result>
</action>
</package>
<package name="Example" extends="Abstract-crud" namespace="/example">
<default-class-ref class="org.ExampleAction" />
</package>
<package name="Example2" extends="Abstract-crud" namespace="/example2">
<default-class-ref class="org.Example2Action" />
<action name="override" class="org.Example2Action" method="override">
<result name="success" type="velocity">somethingelse.vm</result>
</action>
</package>
<package name="SubItem" extends="Abstract-crud" namespace="/example2/subItem">
<default-class-ref class="org.SubItemAction" />
</package>
Of couse something like the above could be combined with wildcards to fit someone’s needs as well.