You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Steven Davelaar <St...@oracle.com> on 2002/09/03 10:04:51 UTC

How to use my own FormPropertyConfig class

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.