You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Kennedy <da...@swanlabs.com> on 2005/02/21 17:48:54 UTC

not working after Validation errors?

Hi folks,
Three days until iteration deadline, and I have a frustrating bug! It's 
almost textbook - I have a simple logon page (username/password) which 
includes a <html:reset> button which works nicely ... unless I press 
'submit' with known bad input and come back to the form with Validation 
errors.

In that case the user can clearly see their input is somehow bad, thanks 
to the message, but when I click 'reset' this time, it does nothing? The 
fields continue to show the bad values.

I've only been using Struts a few days, and this feels like a FAQ, but 
I've not found an answer anywhere. I've a notion the values it's 
resetting too are actually the bad ones still held in the dyna bean, but 
I'm not sure how to correct that.

Any ideas? Please? What is the obvious thing I'm missing?


Gory details; tomcat 5.5.4, struts 1.2.4, jdk1.5.0, red hat 7.2:

struts-config.xml:
==================
   <form-beans>
     <form-bean  name="logonForm"
                 type="org.apache.struts.validator.DynaValidatorForm">
                 <form-property name="username" type="java.lang.String"/>
                 <form-property name="password" type="java.lang.String"/>
     </form-bean>
   </form-beans>
...
     <action path="/logon"
             type="com.swanlabs.action.LogonAction"
             name="logonForm"
             validate="true"
             scope="request"
             input="logon"
             unknown="true">
       <forward name="success" path="/placeholder.jsp"/>
       <forward name="failure" path="/logon"/>
     </action>

validation.xml:
===============
<form-validation>
   <formset>
     <form name="logonForm">
       <field property="username" depends="required">
         <arg0 key="logon.label.username"/>
       </field>
       <field property="password" depends="required">
         <arg0 key="logon.label.password"/>
       </field>
     </form>
   </formset>
</form-validation>


logon.jsp:
==========
   <html:form action="logon.do">
...
   <html:reset titleKey="logon.tooltip.reset" styleClass="buttons">
     <bean:message key="logon.label.reset"/>
   </html:reset>
...
   </html:form>

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


Re: not working after Validation errors?

Posted by Joe Germuska <Jo...@Germuska.com>.
At 4:48 PM +0000 2/21/05, David Kennedy wrote:
>Hi folks,
>Three days until iteration deadline, and I have a frustrating bug! 
>It's almost textbook - I have a simple logon page 
>(username/password) which includes a <html:reset> button which works 
>nicely ... unless I press 'submit' with known bad input and come 
>back to the form with Validation errors.
>
>In that case the user can clearly see their input is somehow bad, 
>thanks to the message, but when I click 'reset' this time, it does 
>nothing? The fields continue to show the bad values.
>
>I've only been using Struts a few days, and this feels like a FAQ, 
>but I've not found an answer anywhere. I've a notion the values it's 
>resetting too are actually the bad ones still held in the dyna bean, 
>but I'm not sure how to correct that.
>
>Any ideas? Please? What is the obvious thing I'm missing?

"reset" means "reset this form to the values it had when the page loaded."

When a page is drawn after validation fails, the initial values are 
set (not blank) so reset reverts to them rather than clearing the 
page.

Personally, I think reset buttons are almost never called for; I know 
I've been bitten a few times by accidentally clicking "reset" (which 
people usually put too close to "submit") and had to refill a form.

If what you want is to clear out all the fields, then either don't 
use the Struts form tags (which will mean that fields are not 
refilled after validation) or write a javascript handler for a 
<button> tag which sets the value of the form fields to blank.  But 
for a typical two field login form, is "reset" even necessary?

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"Narrow minds are weapons made for mass destruction"  -The Ex

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


Re: not working after Validation errors?

Posted by Brian Bezanson <br...@gmail.com>.
David,

What you need to do is to create your own custom handling of "Reset".

In the case of your form, I would NOT use a <HTML:Reset>, instead make
a <HTML:SUBMIT> but have a javascript snippet that sets a value for a
hidden form field, lets call the hidden field "action" and the value
would be 'reset'.

Then in your LoginAction.java, check the value of the form's action
field. If the value is 'reset', reload the original values back from
the database.

As explained earlier, the first time you come into the page, the
values of the form fields are what you set either from a database or
from your default values in the struts-config.xml file. When changes
were made, submitted, and failed validation, the default values of
these fields are the errored values sent with the last form
submission. As you have seen, all the normal reset does is restore
those values to the defaults for the html page. So the first time you
get 'good' defaults and the second time you get 'bad' defaults. By
making your own custom 'reset' button you get more control over the
action.

You could try and fix the errored values for the user in the first
place, but that would get around telling them what fields were wrong
and why.

Hope this helps,

Brian

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


Re: not working after Validation errors?

Posted by Peter Neu <pe...@gmx.net>.
Ok overlooked the main problem in that case :(

Jeff Beal schrieb:
> I think you misunderstood the original problem.  Here's the sequence of 
> events that David *wants* to happen:
> 
>  1) ActionForm gets pre-populated with intial values and/or values from 
> database
>  2) User makes changes to the form that cause validation errors
>  3) The user sees their mistakes, hits "reset"
>  4) The user sees the original values from step 1
> 
> Whether you use request- or session-scoped ActionForms, the step 1 
> values are overwritten in step 2.  Session-scoped ActionForms would 
> actually be worse, because the step 1 values may be gone for the 
> duration of the session.  With request-scoped beans, they can at least 
> hit the "back" button and refresh (depending on other details of the 
> appplication).
> 
> -- Jeff
> 
> Peter Neu wrote:
> 
>> Change scope="request" to scope="session" in order to remember!
>>
>>
>> Jeff Beal schrieb:
>>
>>> The <html:reset/> tag makes no attempt at "remembering" the original 
>>> values of the ActionForm itself, it just includes an HTML input 
>>> element of type 'reset'.  All this does is to remove user edits from 
>>> the current page.  IOTW, the behavior you are describing is exactly 
>>> as expected.
>>>
>>> -- Jeff
> 
> 
> 
> ---------------------------------------------------------------------
> 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: not working after Validation errors?

Posted by Jeff Beal <jb...@webmedx.com>.
I think you misunderstood the original problem.  Here's the sequence of 
events that David *wants* to happen:

  1) ActionForm gets pre-populated with intial values and/or values from 
database
  2) User makes changes to the form that cause validation errors
  3) The user sees their mistakes, hits "reset"
  4) The user sees the original values from step 1

Whether you use request- or session-scoped ActionForms, the step 1 
values are overwritten in step 2.  Session-scoped ActionForms would 
actually be worse, because the step 1 values may be gone for the 
duration of the session.  With request-scoped beans, they can at least 
hit the "back" button and refresh (depending on other details of the 
appplication).

-- Jeff

Peter Neu wrote:
> Change scope="request" to scope="session" in order to remember!
> 
> 
> Jeff Beal schrieb:
> 
>> The <html:reset/> tag makes no attempt at "remembering" the original 
>> values of the ActionForm itself, it just includes an HTML input 
>> element of type 'reset'.  All this does is to remove user edits from 
>> the current page.  IOTW, the behavior you are describing is exactly as 
>> expected.
>>
>> -- Jeff


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


Re: not working after Validation errors?

Posted by Peter Neu <pe...@gmx.net>.
Change scope="request" to scope="session" in order to remember!


Jeff Beal schrieb:
> The <html:reset/> tag makes no attempt at "remembering" the original 
> values of the ActionForm itself, it just includes an HTML input element 
> of type 'reset'.  All this does is to remove user edits from the current 
> page.  IOTW, the behavior you are describing is exactly as expected.
> 
> -- Jeff
> 
> David Kennedy wrote:
> 
>> Hi folks,
>> Three days until iteration deadline, and I have a frustrating bug! 
>> It's almost textbook - I have a simple logon page (username/password) 
>> which includes a <html:reset> button which works nicely ... unless I 
>> press 'submit' with known bad input and come back to the form with 
>> Validation errors.
>>
>> In that case the user can clearly see their input is somehow bad, 
>> thanks to the message, but when I click 'reset' this time, it does 
>> nothing? The fields continue to show the bad values.
>>
>> I've only been using Struts a few days, and this feels like a FAQ, but 
>> I've not found an answer anywhere. I've a notion the values it's 
>> resetting too are actually the bad ones still held in the dyna bean, 
>> but I'm not sure how to correct that.
>>
>> Any ideas? Please? What is the obvious thing I'm missing?
>>
>>
>> Gory details; tomcat 5.5.4, struts 1.2.4, jdk1.5.0, red hat 7.2:
>>
>> struts-config.xml:
>> ==================
>>   <form-beans>
>>     <form-bean  name="logonForm"
>>                 type="org.apache.struts.validator.DynaValidatorForm">
>>                 <form-property name="username" type="java.lang.String"/>
>>                 <form-property name="password" type="java.lang.String"/>
>>     </form-bean>
>>   </form-beans>
>> ...
>>     <action path="/logon"
>>             type="com.swanlabs.action.LogonAction"
>>             name="logonForm"
>>             validate="true"
>>             scope="request"
>>             input="logon"
>>             unknown="true">
>>       <forward name="success" path="/placeholder.jsp"/>
>>       <forward name="failure" path="/logon"/>
>>     </action>
>>
>> validation.xml:
>> ===============
>> <form-validation>
>>   <formset>
>>     <form name="logonForm">
>>       <field property="username" depends="required">
>>         <arg0 key="logon.label.username"/>
>>       </field>
>>       <field property="password" depends="required">
>>         <arg0 key="logon.label.password"/>
>>       </field>
>>     </form>
>>   </formset>
>> </form-validation>
>>
>>
>> logon.jsp:
>> ==========
>>   <html:form action="logon.do">
>> ...
>>   <html:reset titleKey="logon.tooltip.reset" styleClass="buttons">
>>     <bean:message key="logon.label.reset"/>
>>   </html:reset>
>> ...
>>   </html:form>
> 
> 
> 
> ---------------------------------------------------------------------
> 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: not working after Validation errors?

Posted by Jeff Beal <jb...@webmedx.com>.
The <html:reset/> tag makes no attempt at "remembering" the original 
values of the ActionForm itself, it just includes an HTML input element 
of type 'reset'.  All this does is to remove user edits from the current 
page.  IOTW, the behavior you are describing is exactly as expected.

-- Jeff

David Kennedy wrote:

> Hi folks,
> Three days until iteration deadline, and I have a frustrating bug! It's 
> almost textbook - I have a simple logon page (username/password) which 
> includes a <html:reset> button which works nicely ... unless I press 
> 'submit' with known bad input and come back to the form with Validation 
> errors.
> 
> In that case the user can clearly see their input is somehow bad, thanks 
> to the message, but when I click 'reset' this time, it does nothing? The 
> fields continue to show the bad values.
> 
> I've only been using Struts a few days, and this feels like a FAQ, but 
> I've not found an answer anywhere. I've a notion the values it's 
> resetting too are actually the bad ones still held in the dyna bean, but 
> I'm not sure how to correct that.
> 
> Any ideas? Please? What is the obvious thing I'm missing?
> 
> 
> Gory details; tomcat 5.5.4, struts 1.2.4, jdk1.5.0, red hat 7.2:
> 
> struts-config.xml:
> ==================
>   <form-beans>
>     <form-bean  name="logonForm"
>                 type="org.apache.struts.validator.DynaValidatorForm">
>                 <form-property name="username" type="java.lang.String"/>
>                 <form-property name="password" type="java.lang.String"/>
>     </form-bean>
>   </form-beans>
> ...
>     <action path="/logon"
>             type="com.swanlabs.action.LogonAction"
>             name="logonForm"
>             validate="true"
>             scope="request"
>             input="logon"
>             unknown="true">
>       <forward name="success" path="/placeholder.jsp"/>
>       <forward name="failure" path="/logon"/>
>     </action>
> 
> validation.xml:
> ===============
> <form-validation>
>   <formset>
>     <form name="logonForm">
>       <field property="username" depends="required">
>         <arg0 key="logon.label.username"/>
>       </field>
>       <field property="password" depends="required">
>         <arg0 key="logon.label.password"/>
>       </field>
>     </form>
>   </formset>
> </form-validation>
> 
> 
> logon.jsp:
> ==========
>   <html:form action="logon.do">
> ...
>   <html:reset titleKey="logon.tooltip.reset" styleClass="buttons">
>     <bean:message key="logon.label.reset"/>
>   </html:reset>
> ...
>   </html:form>


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