You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ambaris Mohanty <am...@lifestylestores.com> on 2007/06/08 10:54:38 UTC

Extending DynaValidatorForm

Can anyone send me sample code for extending DynaValidatorForm and
implementing reset() method that will clear the text fields on reset.

Thank you,

AM


Re: Extending DynaValidatorForm

Posted by "David Durham, Jr." <da...@gmail.com>.
On 6/11/07, Ambaris Mohanty <am...@lifestylestores.com> wrote:
> My code is as following...
> struts-config.xml
>
> <form-beans>
>         <form-bean name="DynaLoginForm"
> type="org.apache.struts.validator.DynaValidatorForm">
>             <form-property name="username" type="java.lang.String"/>
>             <form-property name="password" type="java.lang.String"/>
>         </form-bean>


Is this something where just adding "initial" will work for you?

<form-property name="username" type="java.lang.String"
initial="&lt;username&gt;"/>

This will affect the behavior of an html-reset control, because it
determines the initial value of new form elements.

Otherwise, if you're going to actually override
DynaValidatorForm.reset, something like this might work for you
(method signature truncated) :

reset(mapping, request) {
   set("username", "<username>");
}

This is one step removed from the html-reset control, because it will
be executed within your servlet context, *not* from within a browser.

What's the actual problem you're trying to solve.

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


RE: Extending DynaValidatorForm

Posted by Ambaris Mohanty <am...@lifestylestores.com>.
Thanks David,
But I need sample code. Can u provide it? I got your logic but finding it
difficult to implement. The main problem is how to get the property name at
runtime. I have many forms that extend the DynaValidatorForm.
Thank you,
AM

-----Original Message-----
From: David Durham, Jr. [mailto:david.durham.jr@gmail.com] 
Sent: Saturday, June 09, 2007 2:46 AM
To: Struts Users Mailing List
Subject: Re: Extending DynaValidatorForm

On 6/8/07, David Durham, Jr. <da...@gmail.com> wrote:
> On 6/8/07, Ambaris Mohanty <am...@lifestylestores.com> wrote:
> > Please someone send me the sample code for extending DynaValidatorForm
and
> > implementing the reset method. I have no idea on how to do it. Please
help.
> > I'm using struts 1.2.9.
> > Thank you,
>
>
> HTML has the concept of a reset button:
>
>    http://www.w3.org/TR/html401/interact/forms.html#reset-button
>
> ...

Hmm, guess you were asking about extending DynaValidatorForm.  I must
have been thinking of some other question that was similar to this
one.  Anyway, a DynaValidatorForm is a DynaBean, so you can call
set("propertyName", "reset Value") from your reset override method.
These API versions aren't exact, but I don't think these classes have
changed much:

http://struts.apache.org/1.3.8/apidocs/org/apache/struts/validator/DynaValid
atorForm.html
http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs/api
/org/apache/commons/beanutils/DynaBean.html

---------------------------------------------------------------------
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: Extending DynaValidatorForm

Posted by Ambaris Mohanty <am...@lifestylestores.com>.
My code is as following...
struts-config.xml

<form-beans>
        <form-bean name="DynaLoginForm"
type="org.apache.struts.validator.DynaValidatorForm">
            <form-property name="username" type="java.lang.String"/>
            <form-property name="password" type="java.lang.String"/>
        </form-bean>

-----Original Message-----
From: David Durham, Jr. [mailto:david.durham.jr@gmail.com] 
Sent: Saturday, June 09, 2007 2:46 AM
To: Struts Users Mailing List
Subject: Re: Extending DynaValidatorForm

On 6/8/07, David Durham, Jr. <da...@gmail.com> wrote:
> On 6/8/07, Ambaris Mohanty <am...@lifestylestores.com> wrote:
> > Please someone send me the sample code for extending DynaValidatorForm
and
> > implementing the reset method. I have no idea on how to do it. Please
help.
> > I'm using struts 1.2.9.
> > Thank you,
>
>
> HTML has the concept of a reset button:
>
>    http://www.w3.org/TR/html401/interact/forms.html#reset-button
>
> ...

Hmm, guess you were asking about extending DynaValidatorForm.  I must
have been thinking of some other question that was similar to this
one.  Anyway, a DynaValidatorForm is a DynaBean, so you can call
set("propertyName", "reset Value") from your reset override method.
These API versions aren't exact, but I don't think these classes have
changed much:

http://struts.apache.org/1.3.8/apidocs/org/apache/struts/validator/DynaValid
atorForm.html
http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs/api
/org/apache/commons/beanutils/DynaBean.html

---------------------------------------------------------------------
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: Extending DynaValidatorForm

Posted by "David Durham, Jr." <da...@gmail.com>.
On 6/8/07, David Durham, Jr. <da...@gmail.com> wrote:
> On 6/8/07, Ambaris Mohanty <am...@lifestylestores.com> wrote:
> > Please someone send me the sample code for extending DynaValidatorForm and
> > implementing the reset method. I have no idea on how to do it. Please help.
> > I'm using struts 1.2.9.
> > Thank you,
>
>
> HTML has the concept of a reset button:
>
>    http://www.w3.org/TR/html401/interact/forms.html#reset-button
>
> ...

Hmm, guess you were asking about extending DynaValidatorForm.  I must
have been thinking of some other question that was similar to this
one.  Anyway, a DynaValidatorForm is a DynaBean, so you can call
set("propertyName", "reset Value") from your reset override method.
These API versions aren't exact, but I don't think these classes have
changed much:

http://struts.apache.org/1.3.8/apidocs/org/apache/struts/validator/DynaValidatorForm.html
http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.6.1/docs/api/org/apache/commons/beanutils/DynaBean.html

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


Re: Extending DynaValidatorForm

Posted by "David Durham, Jr." <da...@gmail.com>.
On 6/8/07, Ambaris Mohanty <am...@lifestylestores.com> wrote:
> Please someone send me the sample code for extending DynaValidatorForm and
> implementing the reset method. I have no idea on how to do it. Please help.
> I'm using struts 1.2.9.
> Thank you,


HTML has the concept of a reset button:

   http://www.w3.org/TR/html401/interact/forms.html#reset-button

As stated in the link above, when a user activates a reset control,
the form values are set to their *inital values*.  This may not be the
reset behavior that you're looking for.

One way to implement a reset button that "clears" form element values
is with JavaScript.  You might do something like:

<button onclick="resetForm(); return false;">Reset</button>

<script type="text/javascript">
    function resetForm() {
        // acquire form reference, e.g.
        var myForm = document.forms['myForm'];

        // loop through elements
        for(var i = 0; i < myForm.elements.length; i++) {
               // check element type and implement reset
               //  your code goes here
        }
    }
</script>

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


RE: Extending DynaValidatorForm

Posted by Ambaris Mohanty <am...@lifestylestores.com>.
Please someone send me the sample code for extending DynaValidatorForm and
implementing the reset method. I have no idea on how to do it. Please help.
I'm using struts 1.2.9.
Thank you,
AM

-----Original Message-----
From: Ambaris Mohanty [mailto:ambaris.mohanty@lifestylestores.com] 
Sent: Friday, June 08, 2007 2:25 PM
To: 'Struts Users Mailing List'
Subject: Extending DynaValidatorForm

Can anyone send me sample code for extending DynaValidatorForm and
implementing reset() method that will clear the text fields on reset.

Thank you,

AM



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