struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Whittaker" <mike_whitta...@ntlworld.com>
Subject RE: RE[Enlightenment]: DynaAF in session scope & checkboxes
Date Fri, 25 Jul 2003 20:42:20 GMT

You are right, I don't.  In fact the CondResetFormPropertyConfig class is
just acting as a flag.
Talk about overkill eh!?

I put in the getReset() method just for the sake of it really, first time
I'd used custom <set-property> Maybe the class will grow with extra
functionality?

Can you suggest a less overkill flag?

--
Mike W.

>
>It is not clear to me that why you need to reset only when
>CondResetFormPropertyConfig.getReset() returns true.
>What's the reason behind this?
>
>Jing
>
>----- Original Message -----
>From: "Mike Whittaker" <mike_whittaker@ntlworld.com>
>To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>Sent: Friday, July 25, 2003 6:22 AM
>Subject: RE[Enlightenment]: DynaAF in session scope & checkboxes
>
>
>>
>> >Has anyone had this combination to work?
>> >I either lose session persistence or (classically) can't clear all
>> >checkboxes.
>> >I've tried overiding reset() in numerous ways.
>> >
>>
>> I think I have found a solution.
>> I hope this will be of interest.  Any comments appreciated.
>>
>> We are told to overide reset() in DynaAF to give desired behaviour ie
>> clearing all checkboxes as browser sends no request parameters for empty
>> boxes.
>>
>> However, since reset is called before form population for that action, we
>> cannot find from Struts methods how many boxes were checked, except if we
>> use request parameters.
>>
>> So we can look for null for the request parameter we are interested in.
>>
>> However this reset method is called for every reference to the form not
>just
>> on submit.  And since the request parameter does not persist, our session
>> scoped form will not persist!
>>
>> Solution:
>> Do nothing in the resest - but shift the exact same logic to an Action
>that
>> is called just on Submit.
>>
>> /*
>> FormPropertyConfig can be subclassed to provide custom reset by property
>set
>> in struts-config:
>> <form-property name="Grades" type="java.lang.String[]"
>> className="com.company.CondResetFormPropertyConfig">
>> <set-property property="reset" value="true" />
>> </form-property> ]
>> */
>>
>> import java.util.*;
>> import javax.servlet.http.*;
>> import org.apache.struts.action.*;
>> import org.apache.struts.config.*;
>> import org.apache.struts.util.*;
>>
>> public class PreferencesAction extends Action {
>>
>> public ActionForward execute(ActionMapping mapping, ActionForm aForm,
>> HttpServletRequest request, HttpServletResponse res) throws Exception {
>>
>> DynaActionForm form = (DynaActionForm)aForm;
>>
>> String name = mapping.getName(); // name of form bean
>> if (name == null) {
>>    return null; // probably throw exception, should always be bean for
>> this action
>> }
>> FormBeanConfig config =
>>    mapping.getModuleConfig().findFormBeanConfig(name); // FBC for this
>> form bean
>> if (config == null) {
>>    return null; // probably throw exception
>> }
>> FormPropertyConfig[] props = config.findFormPropertyConfigs();
>> for (int i = 0; i < props.length; i++) {
>> // reset only if CondResetFPC & getReset() returns true
>> if (props[i] instanceof CondResetFormPropertyConfig &&
>> (((CondResetFormPropertyConfig)props[i]).getReset())) {
>>
>> if(props[i].getName().equals("Grades")) { // trace
>> System.out.println("****Action.perform()****");
>>         System.out.println("PropertyLength
>> \t"+((String[])form.get("Grades")).length);
>>         System.out.println("PropertyType     \t"+props[i].getType());
>>         System.out.println("PropertyName     \t"+props[i].getName());
>> System.out.println("RequestParameter
>> \t"+request.getParameter(props[i].getName()));
>>      }
>>
>> if(request.getParameter(props[i].getName()) == null) {
>> form.set(props[i].getName(), props[i].initial());
>> }
>>
>> }
>>
>> }
>>
>> return mapping.getInputForward();
>> }
>>
>> }
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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


Mime
View raw message