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]

Reply via email to