struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mainguy, Mike" <MMain...@kmart.com>
Subject RE: Re-populating form after validate fails
Date Thu, 05 Feb 2004 13:33:29 GMT
I've seen this happen a couple of times with different people (myself
included).  It seems like the default (expected) behavior is:  "use the bean
value unless it's blank, then use the html"  i.e. if html="" and bean="text"
it should be the bean value if the bean="" and the html="asdasdf" then it
should be "asdasdf".  And if you have html="foo" and bean="bar" then it
should be "bar".




-----Original Message-----
From: Paul Barry [mailto:paul.barry@nyu.edu] 
Sent: Thursday, February 05, 2004 8:24 AM
To: struts-user@jakarta.apache.org
Subject: Re: Re-populating form after validate fails


I finally figured this out.  It was a stupid mistake.  I had <html:text
property="username" value="" />.  The value="" 
overrides what was in the bean.  Once I removed this, problem solved.

Paul Barry wrote:
> If validate fails, your action won't even be processed.  You can't use
> any of the forwards that you may set up for your action, because your 
> action never executes, you can't do a mapping.findForward("failure").  
> Once validate fails, it forwards to the input.  The struts example has 
> validate=false (it uses the default) for the LogonAction.  It uses the 
> validator to validate the form, so that is a different example.
> 
> I found the answer to my extra credit question, you can use
> input="forwardName" in your action if you have inputForward set to true 
> in your controller config.  I have this set up, but it doesn't change 
> any thing.  Here is the log of what happens when I fill in a username 
> and no password:
> 
> Processing a 'POST' for path '/myaccount/loginAction'
> Storing ActionForm bean instance in scope 'request' under attribute 
> key
> 'LoginForm'
> Populating bean properties from this request
> Validating input form properties
> Validation failed, returning to 'myaccount/login'
>
processForwardConfig(ForwardConfig[name=myaccount/login,path=/myaccount/logi
n.do,redirect=false,contextRelative=false]) 
> 
> Processing a 'POST' for path '/myaccount/login'
> Storing ActionForm bean instance in scope 'request' under attribute 
> key
> 'LoginForm'
> Populating bean properties from this request
> Looking for Action instance for class myapp.struts.actions.ForwardAction
> Returning existing Action instance
>  From toString in my ForwardAction -> 
> Path=[/WEB-INF/jsp/myaccount/login.jsp],Form=[Username=sdfdsf,Password=]
>
processForwardConfig(ForwardConfig[name=null,path=/WEB-INF/jsp/myaccount/log
in.jsp,redirect=false,contextRelative=true]) 
> 
> 
> I have removed all the info from these messages to make it easier to
> read.  All of these messages are DEBUG messages that come from the 
> RequestProcessor, except the toString that I am printing out near the 
> end.  This all looks like exactly what I would want to happen.  The 
> original POST goes to loginAction, the validate method is called and 
> fails, so it forwards to myaccount/login.  The form is stored in the 
> request scope.  When I call the toString method after the form has been 
> populated, you can see the username property is populated.  This makes 
> sense.  The request was forwarded from the original action to this 
> action.  The request parameters are still the same as the original 
> request, so when the form is populated, the username field is populated.
> 
> What doesn't make sense to me is that when I look at my form on the 
> HTML
> page (which is /WEB-INF/jsp/myaccount/login.jsp in this case), the 
> username property is not populated.  This doesn't make sense to me.  The 
> html:form tag should see that the form property for username is 
> populated, so therefore the 'html:test property="username"' field should 
> be populated with that value.  What am I missing here?
> 
> 
>>
>> Subject:
>> Re: Re-populating form after validate fails
>> From:
>> hgosper@csc.com.au
>> Date:
>> Wed, 4 Feb 2004 12:50:17 +1100
>> To:
>> "Struts Users Mailing List" <struts-user@jakarta.apache.org>
>>
>>
>> oops, you could be right. I left that out when I was genericising my
>> action tag... just trying to make it more generic.
>>
>> However, my point is still that when validate fails then the errors
>> will not be empty... that is where your action tells struts to forward 
>> as:
>>
>>
>>>  forward = mapping.findForward("failure");
>>
>>
>>
>> and in your struts entry you can see (in my example) that "failure" 
>> is
>> defined as the same form (but it could be anything)
>>
>> an example of this is in the sample struts project in the struts
>> tutorial where the login screen forwards to "welcome" if login was 
>> okay, or back to "login" if it failed.
>>
>> so I'm not sure if the input parameter is responsible for the
>> forward... it could be the default?
>> Cheers,
>> Heya Gosper
>> CSC Australia
>> 212 Northbourne Ave, Braddon ACT 2612
>> Ph: +61 (0) 2 6246 8155  Fax: +61 (0) 2 62468100
>> MOB: 0401 611779
>>
> 


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

-----------------------------------------
This message and its contents (to include attachments) are the property of Kmart Corporation
(Kmart) and may contain confidential and proprietary information. You are hereby notified
that any disclosure, copying, or distribution of this message, or the taking of any action
based on information contained herein is strictly prohibited. Unauthorized use of information
contained herein may subject you to civil and criminal prosecution and penalties. If you are
not the intended recipient, you should delete this message immediately.


---------------------------------------------------------------------
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