struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gemes Tibor <ge...@regens.hu>
Subject Re: DynaActionForm in session scope
Date Fri, 13 Dec 2002 08:15:54 GMT
2002. december 13. 20:00 dátummal Charles ezt írtad:
> Thanks for your help. But I'm still a little confused. How do you extend a
> DynaActionForm? I thought it was created on the fly.

Only the properties are created on the fly, the class itself is 
org.apache.struts.action.DynaActionForm.

So here is the rough overview of what I have done.

public class CondResetDynaActionForm extends DynaActionForm {
    /** Reset the property to its initial value conditionally. 
     **/
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        String name = mapping.getName();
        if (name == null) {
            return;
        }
        FormBeanConfig config =
            mapping.getApplicationConfig().findFormBeanConfig(name);
        if (config == null) {
            return;
        }
        FormPropertyConfig props[] = config.findFormPropertyConfigs();
        for (int i = 0; i < props.length; i++) {
            // reset only if not CondResetFPC or getReset() returns true
	    if (!(props[i] instanceof CondResetFormPropertyConfig) || 
(((CondResetFormPropertyConfig)form).getReset())
                set(props[i].getName(), props[i].initial());
        }
    }
}

Extend the FormPropertyConfig with a reset property. (homework :)

> Also you mentioned about using the set-property tags. Please forgive my
> ignorance, but could you provide me with a working example of how this
> set-property tags can be used to present the reset() being called?

If you want to leave the reset() as it was originally, you declare your 
form-bean as DynaActionForm. If you want your own reset to be executed, 
declare it as CondResetDynaActionForm.
The set-property could be used to determine per form-property whether you want 
to reset it or not. But in this case you have to specify, that this is your 
FPC class, not the original one as the original FPC does not have "reset" 
property. 
<form-bean name="myForm"
                   type="com.yourcompany.struts.CondResetDynaActionForm">
	<form-property name="myProp1" type="java.lang.String"
		className="com.yourcompany.struts.CondResetFormPropertyConfig">
		<set-property name="reset" value="false" />
	 </form-property>



Hth,

Tib

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message