on the first hit to you personForm.do, or whatever (i presume you're not hitting the jsp directly at any point), the backing Action class should get the values from the validUser bean and populate the PersonDetailsForm bean, which then gets used by the jsp. it sounds like maybe you're using the values in the validUser bean directly with the struts <html:form...> tags. i think what you have like this: <html:text name="validUser"...
maybe should be this: <html:text name="PersonDetailsForm"... so the validUser bean is used by the Action classes, and the PersonDetailsForm bean by the jsp, and logic in the Action classes dictates when and how data is transfered between the two. validation failure just redisplays the form (which should display what the user just tried to enter, not the original data from validUser). validation success might call another action that updated validUser with the new info from PersonDetailsForm. at least i think so, if i understand you correctly. works like that in similar situations here. -----Original Message----- From: Frank Burns [mailto:[EMAIL PROTECTED] Sent: Sunday, March 07, 2004 9:06 PM To: Struts Users Mailing List Subject: Re: Struts starter John, This is very good ... Please bear with me for a final bit of clarification. I neglected to explain that I had already created what you call the "PopulatePersonAction" in your example and also set up the struts-config as you suggested. I have the equivalent of this: <form-beans> <form-bean name="personalDetailsForm" type="com.foo.PersonalDetailsForm" /> </form-beans> <action path="/PersonForm" type="com.foo.PopulatePersonAction" name="personalDetailsForm" scope="request" validate="true" input="/pages/PersonalDetails.jsp"> <forward name="success" path="/pages/TheNextPageToCall.jsp" /> </action> Note that the value assigned to the "input" parameter is "/pages/PersonalDetails.jsp". In my PersonalDetails.jsp the action in the <html:form> tag is PopulatePersonAction. When I initially call PersonalDetails.jsp, there is already a validUser bean in the session scope, representing the current, logged-in user. On first being displayed, I want the fields of PersonalDetails.jsp to be populated with data from the validUser bean. Say I have an emailAddress field that I populate, like this: <html:text name="validUser" property="emailAddress" size="20" />. Let's say the user enters some invalid data into the email address field and then clicks the submit button. The controller calls the personalDetailsForm and executes its validate() method, which fails. Because of the failure, the controller then calls PersonalDetails.jsp -- because it is the value in the "input" parameter for the /PersonForm action defined in struts-config. The newly called PersonalDetails.jsp now has access to the PersonalDetailsForm form bean containing the data entered by the user. HOWEVER, HOW WILL THE NEWLY CALLED PersonalDetails.jsp POPULATE THE emailAddress FIELD WITH THE VALUE THAT THE USER ENTERED? Won't it just re-display the value from the validUser bean? Because that's how it's defined in the page, i.e., <html:text name="validUser" property="emailAddress" size="20" />. Thanks, Frank. ----- Original Message ----- From: "John McGrath" <[EMAIL PROTECTED]> To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]> Sent: Sunday, March 07, 2004 10:19 PM Subject: RE: Struts starter > i'm a relative newcomer myself, but i think the part you're missing is > an Action class. > > Put an entry in struts-config something like this: > > <action path="/PersonForm" type="com.foo.PopulatePersonAction" > name="PersonalDetailsForm" scope="request" validate="true"> > <forward name="success" path="/pages/PersonalDetails.jsp" /> > </action> > > Then write a PopulatePersonAction (or whatever) class that extends the > struts Action class. When you hit /PersonForm.do, PopulatePersonAction > can hit a datastore, create a DTO (validUser or whatever), and > transfer the values from your DTO to the form (probably using the > apache BeanUtils classes). When the Action class forwards to a mapping > ('success'), the struts tags in the form will be able to access the > bean that was created by the Action class. > > likewise, if you have the form submitting to a struts-config entry > that maps to another Action class, the validate method will be called > before the 'execute' method of the action mapped to the *.do that form > is submitting to. because the validate method is called after the form > bean has been populated, but before the Action class' 'execute' method > has been called, when the validate method forwards back to the input > form (the default behavior on failure to validate), i think the user's > newly submitted fields should be prepopulated, so long as you used the > <html:form...> tags for the form. > > This seemed unnecessarily complicated to me when i started using > struts, but we soon found that if we kept things suitably atomic, the > extra effort up front quickly paid of in code reusability (we reuse > our action classes like mad) and standardization. good luck! > > john > > > -----Original Message----- > From: Frank Burns [mailto:[EMAIL PROTECTED] > Sent: Sunday, March 07, 2004 4:15 PM > To: [EMAIL PROTECTED] > Subject: Struts starter > > > Hi, > I'm in the middle of working with my first application using Struts > and desperately need some help. I've read nearly all of Ted Husted's > "Struts In Action" book and browsed the mailing list archives but have > not found a solution for what I want to do. I mention this to let you > know that I have already tried hard, unsuccessfully, to find an answer > to what seems to me to be a basic requirement. However, I may be > struggling with my own misunderstanding! > > HERE'S THE BACKGROUND > > I have a session bean (validUser) and I want to use its properties to > initially populate a "PersonalDetails" form. Then I want to use the > validate() method of the related ActionForm (PersonalDetailsForm) to > check the newly submitted details and, if failing validation, > redisplay them in the PersonalDetails form, so that the user can > correct them. > > HERE'S THE QUESTION: > > Where and how do I "initialize" (prepopulate) the form fields with the > properties from the validUser bean, but then enable them to be > populated with the information entered by the user when the form fails > validation? > > HERE'S WHAT I'VE TRIED > > I've tried using <html:text ...> tags in the form, but they only seem > to accept values from either the default form bean or from a specified > bean > -- so that seems only to a give a single source for populating the > fields. > > Thanks, > > Frank. > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

