You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Spencer <pa...@apache.org> on 2004/08/27 17:10:03 UTC

Reseting one field on a DynaActionForm to it's initial value?

How can I reset one field on a DynaActionForm to it's initial value?

Paul Spencer


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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Paul Spencer <pa...@apache.org>.
Hubert,
Thank you for your help!  Below is the resulting code.

   DynaActionForm inputForm = (DynaActionForm) form;
   FormBeanConfig formConfig = ModuleUtils.getInstance()
      .getModuleConfig(request)
      .findFormBeanConfig(mapping.getAttribute());
   FormPropertyConfig formProperty = formConfig
      .findFormPropertyConfig(FORM_PROPERTY_SORTORDER);
   inputForm.set(formProperty.getName(), formProperty.initial());

Paul Spencer
Hubert Rabago wrote:

> In this case, you're dealing with a submitted form, and the form name
> is available through mapping.getAttribute().
> 
> hth,
> Hubert
> 
> On Fri, 27 Aug 2004 11:58:44 -0400, Paul Spencer <pa...@apache.org> wrote:
> 
>>My web application has a common form that contains the property
>>"SortOrder".  The value of the property is a list of fields used by the
>>Action for sorting a list.  I want my Action to reset the value of the
>>"SortOrder" to it's initial value, as defined in struts-config.xml.
>>
>>When a value of the SortOrder is invalid for the Action, my sort method
>>throws an exception.  In addition I do not want to "default" the
>>"SortOrder" to the last one used.  Thus, I want the Action to reset the
>>"SortOrder" every time.  Since the form contains other properties, I can
>>not reset the form.
>>
>>As an example:
>>I have 2 Actions, EmployeeAction and TruckAction.
>>Valid values for "SortOrder" in EmployeeAction are "id, name, hireDate".
>> Valid values for "SortOrder" in TruckAction are "id, purchaseDate, and
>>mileage".
>>
>>
>>
>>Paul Spencer
>>Hubert Rabago wrote:
>>
>>
>>>Unfortunately, you'll have to provide it.  ActionForms don't carry the
>>>name they were declared with.  The only object with that information
>>>is FormBeanConfig.
>>>There's no surefire failproof way to know what name, if any, is
>>>associated with a DynaActionForm with just an instance of it.
>>>
>>>What are you trying to do?  There may be other (better) ways to do
>>>what you're trying to without messing with FormBeanConfigs and
>>>FormPropertyConfigs.
>>>
>>>On Fri, 27 Aug 2004 11:27:45 -0400, Paul Spencer <pa...@apache.org> wrote:
>>>
>>>
>>>>Hubert,
>>>>Where do I get the name of the form?
>>>>
>>>>Paul Spencer
>>>>
>>>>
>>>>
>>>>
>>>>Hubert Rabago wrote:
>>>>
>>>>
>>>>
>>>>>Well, it ain't that easy:
>>>>>
>>>>>       // code taken from DynaActionFormClass
>>>>>       DynaActionForm formBean = (DynaActionForm) form;
>>>>>       FormBeanConfig config =
>>>>>ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
>>>>>       FormPropertyConfig props[] = config.findFormPropertyConfigs();
>>>>>       for (int i = 0; i < props.length; i++) {
>>>>>           if ("fieldName".equals(props[i].getName())) {
>>>>>               formBean.set(props[i].getName(), props[i].initial());
>>>>>               break;
>>>>>           }
>>>>>       }
>>>>>
>>>>>
>>>>>
>>>>>On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
>>>>>
>>>>>
>>>>>
>>>>>>How can I reset one field on a DynaActionForm to it's initial value?
>>>>>>
>>>>>>Paul Spencer
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>>For additional commands, e-mail: user-help@struts.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 



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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Hubert Rabago <hr...@gmail.com>.
In this case, you're dealing with a submitted form, and the form name
is available through mapping.getAttribute().

hth,
Hubert

On Fri, 27 Aug 2004 11:58:44 -0400, Paul Spencer <pa...@apache.org> wrote:
> My web application has a common form that contains the property
> "SortOrder".  The value of the property is a list of fields used by the
> Action for sorting a list.  I want my Action to reset the value of the
> "SortOrder" to it's initial value, as defined in struts-config.xml.
> 
> When a value of the SortOrder is invalid for the Action, my sort method
> throws an exception.  In addition I do not want to "default" the
> "SortOrder" to the last one used.  Thus, I want the Action to reset the
> "SortOrder" every time.  Since the form contains other properties, I can
> not reset the form.
> 
> As an example:
> I have 2 Actions, EmployeeAction and TruckAction.
> Valid values for "SortOrder" in EmployeeAction are "id, name, hireDate".
>  Valid values for "SortOrder" in TruckAction are "id, purchaseDate, and
> mileage".
> 
> 
> 
> Paul Spencer
> Hubert Rabago wrote:
> 
> > Unfortunately, you'll have to provide it.  ActionForms don't carry the
> > name they were declared with.  The only object with that information
> > is FormBeanConfig.
> > There's no surefire failproof way to know what name, if any, is
> > associated with a DynaActionForm with just an instance of it.
> >
> > What are you trying to do?  There may be other (better) ways to do
> > what you're trying to without messing with FormBeanConfigs and
> > FormPropertyConfigs.
> >
> > On Fri, 27 Aug 2004 11:27:45 -0400, Paul Spencer <pa...@apache.org> wrote:
> >
> >>Hubert,
> >>Where do I get the name of the form?
> >>
> >>Paul Spencer
> >>
> >>
> >>
> >>
> >>Hubert Rabago wrote:
> >>
> >>
> >>>Well, it ain't that easy:
> >>>
> >>>        // code taken from DynaActionFormClass
> >>>        DynaActionForm formBean = (DynaActionForm) form;
> >>>        FormBeanConfig config =
> >>>ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
> >>>        FormPropertyConfig props[] = config.findFormPropertyConfigs();
> >>>        for (int i = 0; i < props.length; i++) {
> >>>            if ("fieldName".equals(props[i].getName())) {
> >>>                formBean.set(props[i].getName(), props[i].initial());
> >>>                break;
> >>>            }
> >>>        }
> >>>
> >>>
> >>>
> >>>On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
> >>>
> >>>
> >>>>How can I reset one field on a DynaActionForm to it's initial value?
> >>>>
> >>>>Paul Spencer
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>For additional commands, e-mail: user-help@struts.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Paul Spencer <pa...@apache.org>.
My web application has a common form that contains the property 
"SortOrder".  The value of the property is a list of fields used by the 
Action for sorting a list.  I want my Action to reset the value of the 
"SortOrder" to it's initial value, as defined in struts-config.xml.

When a value of the SortOrder is invalid for the Action, my sort method 
throws an exception.  In addition I do not want to "default" the 
"SortOrder" to the last one used.  Thus, I want the Action to reset the 
"SortOrder" every time.  Since the form contains other properties, I can 
not reset the form.

As an example:
I have 2 Actions, EmployeeAction and TruckAction.
Valid values for "SortOrder" in EmployeeAction are "id, name, hireDate". 
  Valid values for "SortOrder" in TruckAction are "id, purchaseDate, and 
mileage".

Paul Spencer
Hubert Rabago wrote:

> Unfortunately, you'll have to provide it.  ActionForms don't carry the
> name they were declared with.  The only object with that information
> is FormBeanConfig.
> There's no surefire failproof way to know what name, if any, is
> associated with a DynaActionForm with just an instance of it.
> 
> What are you trying to do?  There may be other (better) ways to do
> what you're trying to without messing with FormBeanConfigs and
> FormPropertyConfigs.
> 
> On Fri, 27 Aug 2004 11:27:45 -0400, Paul Spencer <pa...@apache.org> wrote:
> 
>>Hubert,
>>Where do I get the name of the form?
>>
>>Paul Spencer
>>
>>
>>
>>
>>Hubert Rabago wrote:
>>
>>
>>>Well, it ain't that easy:
>>>
>>>        // code taken from DynaActionFormClass
>>>        DynaActionForm formBean = (DynaActionForm) form;
>>>        FormBeanConfig config =
>>>ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
>>>        FormPropertyConfig props[] = config.findFormPropertyConfigs();
>>>        for (int i = 0; i < props.length; i++) {
>>>            if ("fieldName".equals(props[i].getName())) {
>>>                formBean.set(props[i].getName(), props[i].initial());
>>>                break;
>>>            }
>>>        }
>>>
>>>
>>>
>>>On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
>>>
>>>
>>>>How can I reset one field on a DynaActionForm to it's initial value?
>>>>
>>>>Paul Spencer
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 



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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Hubert Rabago <hr...@gmail.com>.
Unfortunately, you'll have to provide it.  ActionForms don't carry the
name they were declared with.  The only object with that information
is FormBeanConfig.
There's no surefire failproof way to know what name, if any, is
associated with a DynaActionForm with just an instance of it.

What are you trying to do?  There may be other (better) ways to do
what you're trying to without messing with FormBeanConfigs and
FormPropertyConfigs.

On Fri, 27 Aug 2004 11:27:45 -0400, Paul Spencer <pa...@apache.org> wrote:
> Hubert,
> Where do I get the name of the form?
> 
> Paul Spencer
> 
> 
> 
> 
> Hubert Rabago wrote:
> 
> > Well, it ain't that easy:
> >
> >         // code taken from DynaActionFormClass
> >         DynaActionForm formBean = (DynaActionForm) form;
> >         FormBeanConfig config =
> > ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
> >         FormPropertyConfig props[] = config.findFormPropertyConfigs();
> >         for (int i = 0; i < props.length; i++) {
> >             if ("fieldName".equals(props[i].getName())) {
> >                 formBean.set(props[i].getName(), props[i].initial());
> >                 break;
> >             }
> >         }
> >
> >
> >
> > On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
> >
> >>How can I reset one field on a DynaActionForm to it's initial value?
> >>
> >>Paul Spencer
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Paul Spencer <pa...@apache.org>.
Hubert,
Where do I get the name of the form?

Paul Spencer


Hubert Rabago wrote:

> Well, it ain't that easy:
> 
>         // code taken from DynaActionFormClass
>         DynaActionForm formBean = (DynaActionForm) form;
>         FormBeanConfig config =
> ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
>         FormPropertyConfig props[] = config.findFormPropertyConfigs();
>         for (int i = 0; i < props.length; i++) {
>             if ("fieldName".equals(props[i].getName())) {
>                 formBean.set(props[i].getName(), props[i].initial());
>                 break;
>             }
>         }
> 
> 
> 
> On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
> 
>>How can I reset one field on a DynaActionForm to it's initial value?
>>
>>Paul Spencer
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 



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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Hubert Rabago <hr...@gmail.com>.
By the way, this code works in 1.2.  In 1.1, I think you'll only have
to change the ModuleUtils.getInstance() with RequestUtils.

On Fri, 27 Aug 2004 10:21:32 -0500, Hubert Rabago <hr...@gmail.com> wrote:
> Well, it ain't that easy:
> 
>        // code taken from DynaActionFormClass
>        DynaActionForm formBean = (DynaActionForm) form;
>        FormBeanConfig config =
> ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
>        FormPropertyConfig props[] = config.findFormPropertyConfigs();
>        for (int i = 0; i < props.length; i++) {
>            if ("fieldName".equals(props[i].getName())) {
>                formBean.set(props[i].getName(), props[i].initial());
>                break;
> 
> 
>            }
>        }
> 
> On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
> > How can I reset one field on a DynaActionForm to it's initial value?
> >
> > Paul Spencer
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

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


Re: Reseting one field on a DynaActionForm to it's initial value?

Posted by Hubert Rabago <hr...@gmail.com>.
Well, it ain't that easy:

        // code taken from DynaActionFormClass
        DynaActionForm formBean = (DynaActionForm) form;
        FormBeanConfig config =
ModuleUtils.getInstance().getModuleConfig(request).findFormBeanConfig("myFormName");
        FormPropertyConfig props[] = config.findFormPropertyConfigs();
        for (int i = 0; i < props.length; i++) {
            if ("fieldName".equals(props[i].getName())) {
                formBean.set(props[i].getName(), props[i].initial());
                break;
            }
        }



On Fri, 27 Aug 2004 11:10:03 -0400, Paul Spencer <pa...@apache.org> wrote:
> How can I reset one field on a DynaActionForm to it's initial value?
> 
> Paul Spencer
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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