struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Barett McGavock <bmcgav...@pulvertech.com>
Subject RE: struts repopulate bug?
Date Wed, 05 May 2004 02:15:22 GMT
Hi Dana,

If I had only one guess as to the problem, I'd say there was a mismatch
between a JSP tag versus what was defined in struts-config. I've found my
silent errors most often trace back to JSP tags. This could be scope-related
but is more likely the name. The name attribute of the action tag
(struts-config) must match the name attribute of the form-bean tag
(struts-config). The action attribute of the html:form tag (JSP) must match
the path attribute of the action tag (struts-config). If the html:text or
other output elements are Struts tags and inside the form tag, you won't
need to specify the name attribute, just the property attribute. The JSP tag
names are often derided as poorly named.

Basic requirements for keeping an ActionForm contents:
- Must have your ActionForm defined in struts-config.xml
- Action must have this ActionForm associated in struts-config.xml.
- You should work with the ActionForm passed into the action.
- You should have an <html:form> tag configured to point to an action with
the form declared. (Don't forget to define the html JSP tag name.)

Beyond that, you might also compare your struts-config, jsp, and action to
some existing samples. I use the feature you mention in every one of my many
Struts modules and it works perfectly for me.

If you could give more concrete examples from the struts-config.xml, JSP,
and action files, we could probably be more helpful. Helpful stuff from
struts-config: your form, action, and action-mappings; from the JSP:
html:form tag and any fields, along with the definitions at the top. The
execute/perform method of your Action.

FYI: To know whether you're redirecting to the form, the form mapping must
have a redirect=true attribute in struts-config.xml.

B

> -----Original Message-----
> From: Dana Hata [mailto:estespark@141.com] 
> Sent: Tuesday, May 04, 2004 6:38 PM
> To: Struts Users Mailing List
> Subject: Re: struts repopulate bug?
> 
> 
> Answers to the questions below...
> 
> I spent 10 hours on it so far, so I've tried many things.  
> Now I did see the Action errors listed in the JSP.  Either 
> Struts is not putting the form bean on the request/session, 
> or it's not populating what it did put on the request/session 
> with was it found in the submitted form bean.
> 
> Dana
> 
> On Tue, 2004-05-04 at 21:26, Riyad Kalla wrote:
> > Dana,
> > Yes Struts should and does do this. It actually does this so well, 
> > that
> > for login forms you need to manually clear the beans or else it 
> > repopulates the values :)
> > 
> > 1) Are you syncing up the names/properties of your fields 
> on your JSP
> > page in the form with the property names of the Form?
> > .. Java snippet ..
> > public String getUserName();
> > public void setUserName(String userName);
> > 
> > ... JSP Snippet ...
> > <html:text name="userForm" property="userName" />
> > 
> 	Yes.  I am following Struts' strict naming conventions.
> 
> > 2) Did you implement your reset method cleanly?
> 	Yes.
> > 
> > 3) Is your validate method straight forward?
> > if(userName == null || userName.length() == 0)
> >   // make/add some errors
> > return actionErrors;
> 	Yes.
> > 
> > 4) How is your action defined in your struts-config? Did 
> you specify a
> > scope for the bean? Have you tried NOT specifying the scope?
> > 
> 	I have tried both session and request, and neither 
> worked, though it shouldn't matter which one you choose, no?
> 
> > I want to reassure you that Struts does this very well and doesn't 
> > need
> > you to hack around it, so if this is not working for you, 
> we just need 
> > to keep trying.
> > 
> > Dana Jeffrey Hata wrote:
> > 
> > >I'm using Struts with WSAD, and I am attempting something very 
> > >simple, which should happen automagically.  Basically, I 
> just need to 
> > >have the form re-populate after submitting a form which 
> doesn't pass 
> > >the form bean's validate method.  Should happen without 
> any special 
> > >coding from me, as this is supposed to be a feature of 
> struts.  Well, 
> > >it didn't happen for me.  I checked things like form-bean 
> scope.  By 
> > >plugging in some strategically placed System.outs, I realized that 
> > >struts was creating a new formbean object, and populating it, but 
> > >when it came back to my JSP, that was using a different formbean 
> > >object.  Shouldn't it be getting the form bean which (should have 
> > >been) placed in the request/session by the actionservlet?  
> Well, it 
> > >apparently wasn't, because the way I got it to work was simply 
> > >putting the following line at the end of my formbean validate():
> > >
> > >request.setAttribute(<my formbean name>,this);
> > >
> > >This made everhything work, so my question is, why the hell didn't 
> > >struts do this?  Isn't it supposed to?  Is there anything I could 
> > >have done to make struts not do this, or maybe place a 
> different form 
> > >bean instance on the request?  It works now, but I don't 
> like hacks.
> > >
> > >Thanks in advance,
> > >
> > >Dana
> > >
> > 
> >---------------------------------------------------------------------
> > >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


Mime
View raw message