-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thom,

Thom Burnett wrote:
> I'm working on an application that uses several jsp pages to gather
> one set of information before it really does anything with it.
> Ideally, the first form gets validated before the user can get to the
> second form and that must be validated before the third .... And of
> course all of this must work if the user hits the browser's
> navigation buttons.

This is a pretty standard multi-page form flow. I assume that you are
using a single form with each "page" separated-out in the validation one
way or another. If not, consider doing that. I switched from
hand-written form beans to dynamic form beans over the past year or so
and haven't looked back. They support this paging concept, and work very
well with the commons-validator plug-in, so you can write your
validations in a declarative way instead of hand-coding everything.

At any rate, let's move on.

> Before I added any validation at all, I found that when I filled out one
> page and went on to the next page, I'd lose whatever was added in the first
> page unless I put the sessionForm as an attribute.

I think what you want to do is one of the following:

1. Name each form something different, and set them all to
   scope="session". Collect all of the forms from the session in your
   final "do it" action.
2. Write an action to "save" the validated data from each page of your
   multi-page form somewhere (like the session) in either a custom data
   bean or something like that. Then, pull that data out in your
   final "do it" action.
3. Merge all your separate forms into a single form and validate based
   upon the current "page". You can stop validation at any point when
   you hit the end of the "page" in your validation by simply returning
   from the validation method somewhere in the middle. Just add a
   "page" property to your bean and submit the current page as a hidden
   form element. Then, use that value to determine where to stop
   validation. This is how the dynamic, multi-page form beans do things.

> Simply specifying that
> the form was in session scope didn't keep the information around.

That shouldn't be the case. Are you sure you were using the correct
session attribute key? That key should match the "name" attribute of the
action mapping.

> So maybe the use of the Javascript to fill input values is killing 
> something that struts is trying to do. I just know that without this,
> I didn't keep information between requests.

Aah, the plot thickens: you are using Javascript to re-populate your
form fields? Yuck. Don't do that. Struts is perfectly capable of doing
that for you. Turn off all that javascript weirdness until you get this
issue solved, then re-add any javascript you think you still need.

> The reason for overriding the validate method was to set the sessionForm
> attribute. I was also just starting to try to use the
> ValidateForm.setPage().
> As I understand it, that field (page) should enable me to have validation
> done only on parts of the form. I haven't seen any examples and am just
> trying it out as we speak.

Yup. This is really the way to go.

>  <% AllDonationInformationFormBean3 sessionForm =
> (AllDonationInformationFormBean3)request.getAttribute("sessionForm") ;
>     if(sessionForm == null) sessionForm = new
> AllDonationInformationFormBean3() ; %>

Okay, the "sessionForm" should actually be called "donorBean". You
should also be getting it from the session (duh -- was that a typo?). Do
it like this:

<%
    AllDonationInformationFormBean3 donorBean =
      (AllDonationInformationFormBean3)
      session.getAttribute("donorBean");
    if(null == donorBean)
      donorBean = new ...();
%>

>        <select name="salutation"/>
>           <option value="Mr.">Mr</option>
>           <option value="Ms.">Ms</option>
>        </select>

You aren't pre-selecting this field based upon what is in the bean. Did
you mean to do that?

>        <input type="text" name="firstname" value="<%=
> sessionForm.getFirstname() %>" /><br/>

Okay, this /is/ what you should be doing, except using my example, I
used "donorBean" instead of "sessionForm". If you add javascript on top
of this, you are just going to confuse the hell out of yourself.

>        <font color="red">*Last Name:        </font>
>        <input type="text" name="last"  value="<%= sessionForm.getLast()

Just a matter of style... why do you have "firstname" versus "last"? I
would recommend "lastname" in this case since it's pretty much the same
thing as the "firstname". Again, that's just a matter of style, really.
Although, if your form is expecting "firstname" and "lastname", then
this is a bug.

Although it /is/ just a matter of style, I think it's good to be
consistent because it reduces the chances of an accidental bug popping up.

Hope this helps,
- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFUNoh9CaO5/Lv0PARArkFAJ4sGAG7GttGAE+l/3/NrGIO/1vD6gCaAjaU
ZfVQBTr/eJefPw6d707U22w=
=poVi
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to