struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Davelaar <Steven.Davel...@oracle.com>
Subject How to use my own FormPropertyConfig class
Date Tue, 03 Sep 2002 08:04:51 GMT
Struts 1.1 beta 2,

Hi,

I want to be able to set custom properties on the <form-property>
element like this.

  <form-bean 
    name="deptForm"
    dynamic="true"
    type="org.apache.struts.action.DynaActionForm">

    <form-property 
      name="Deptno" 
      type="java.lang.Integer">
      <set-property property="persistentAttribute"
value="DepartmentNo"/>
    </form-property>  

I dived into the source code and found out that class
org.apache.struts.config.FormPropertyConfig is used to hold this
information. So, I assume I have to create a subclass of this class and
add get/set methods for all my custom properties. 

The problem is: how do I tell Struts to use my custom
<My>FormPropertyConfig class?

I already found out the following:

- Class org.apache.struts.config.ConfigRuleSet contains the information
that instantiates the FormPropertyConfig class in method
addRuleInstances:

        digester.addObjectCreate
            ("struts-config/form-beans/form-bean/form-property",
             "org.apache.struts.config.FormPropertyConfig",
             "className");

- ActionServlet instantiates ConfigRuleSet in method initConfigDigester.

I tried to subclass ConfigRuleSet and overwrite method addRuleInstances.
Unfortunately, this does not compile because this method uses inner
final classes like AddDataSourcePropertyRule and others. 

So, my question is: how do I drive Struts to use my own
FormPropertyConfig class. The dtd supports custom properties on this, so
it should be possible. 

In general, looking at the code in ConfigRuleSet, it would be a great
improvement if Struts provided a simple (xml-based) override mechanism
to all classes that are specified in ConfigRuleSet, not just
ActionMapping. Even if I wouldn't have run into the problem of the inner
final classes, I have to duplicate a lot of code in the two methods I
need to overwrite (addRuleInstances and initConfigDigester).

Any help is greatly appreciated!

Thanks,
Steven Davelaar.

Mime
View raw message