I ran into a problem trying to subclass
org.apache.struts.config.FormBeanConfig.  Here is essentially what I was
trying:

<form-bean name="myForm" dynamic="true"
type="org.apache.struts.action.DynaActionForm"
className="mycompany.MyFormBeanConfig">
.
.
.
</form-bean>


public class MyFormBeanConfig extends
org.apache.struts.config.FormBeanConfig
{
.
.
.
}

The error I was getting was a "Cannot find message resources under key"
exception.  After removing the use of bean:message tags from my login page,
I then saw the true error, "ClassCastException for
mycompany.MyFormBeanConfig".  This led me to the following code in
ActionServlet.java:

    /**
     * Perform backwards-compatible configuration of an ActionFormBeans
     * collection, and expose it as a servlet context attribute (as was
     * used in Struts 1.0).  Note that the current controller code does
     * not (and should not) reference this attribute for any reason.
     *
     * @param config The ApplicationConfig object for the default app
     *
     * @since Struts 1.1
     * @deprecated Will be removed in a release after Struts 1.1.
     */
    private void defaultFormBeansConfig(ApplicationConfig config) {

        FormBeanConfig fbcs[] = config.findFormBeanConfigs();
        ActionFormBeans afb = new ActionFormBeans();
        afb.setFast(false);
        for (int i = 0; i < fbcs.length; i++) {
            afb.addFormBean((ActionFormBean) fbcs[i]);
        }
        afb.setFast(true);
        getServletContext().setAttribute(Action.FORM_BEANS_KEY, afb);

    }

Since this code blindly casts a FormBeanConfig to an ActionFormBean, I
really needed to subclass from ActionFormBean instead of FormBeanConfig

The documentation for the "form-bean" element in
http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd
<http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd>   seems
misleading in that it states that if you specify "className" for a
form-bean" element, that the object must be a subclass of
org.apache.struts.config.FormBeanConfig.

Just a heads up in case anyone wants to use the <set-property> element with
a <form-bean> element, and needs to subclass FormBeanConfig to do so.

Reply via email to