Re: Starting validation

2006-11-07 Thread Christopher Schultz
-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 ...();
%>

>
>   Mr
>   Ms
>

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

>

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.

>*Last Name:
>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]



Re: Starting validation

2006-11-07 Thread Thom Burnett

Here's a snippet of one of the jsp files.

I'd almost forgotten myself that I added the getAttribute("sessionForm")
some time ago.
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.

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. Simply specifying that
the form was in session scope didn't keep the information around. In my
research, this was something that some people did and others didn't. I
wasn't clear on when or why.

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.

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.

 <% AllDonationInformationFormBean3 sessionForm =
(AllDonationInformationFormBean3)request.getAttribute("sessionForm") ;
if(sessionForm == null) sessionForm = new
AllDonationInformationFormBean3() ; %>
 
   
 New Account Registration
   
   
 
 Donor
Information
 
 *Indicates required field
 
   Title
   
  Mr
  Ms
   
 
 
   *First Name: 
   

   *Last Name:
   



On 11/7/06, Christopher Schultz <[EMAIL PROTECTED]> wrote:


-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thom,

Thom Burnett wrote:
> With that fixed I can take out the sub class' validate() method and
still
> get a set of errors.

That's good, I guess. What do you mean, the subclass's validate method?
I didn't realize that you had multiple levels of validation being
performed.

> However, getting errors still depopulate's the form's fields.

That shouldn't happen. Lemmie look at your JSP source again...

Ah. You didn't provide any of the HTML code that contains the 
elements. Could you post a representative sample?

> Again, I can
> fix that by overriding the validate method (calling super) and that's
not a
> horrible solution

Yeah... don't do that. You should be able to work directly with the bean
that you already have. No need to go through any acrobatics like this.

Just so I know, what is the superclass for this bean and what does its
super.validate method do that you aren't doing in the subclass?

Come to think of it, why are you overriding the superclass's validate
method in the first place? And... if you are overriding it, why aren't
you calling that superclass method first thing in your overidden method
implementation?

If you have a "base form bean" that contains some utility methods, you
should not have to call super.validate(). On the other hand, if you have
a super class bean that needs its validation done /too/, then you should
do this:

public ActionErrors validate(...)
{
   ActionErrors errors = super.validate(...);

   // Now perform your own validation.

   return errors;
}

> As near as I can see the form is being named and associated correctly
but I
> must be missing something.

It looks like validate() is being called, otherwise you wouldn't be
getting error messages. Since your action mapping names the bean /and/
the input attribute is associated with the mapping (i.e. there's no
redirect), that bean (including its invalid input) ought to be available
in the session (as per your 'scope' preference).

Post your JSP code around your  elements and let me have a look.

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

iD8DBQFFUM8a9CaO5/Lv0PARAsyxAJ9YtgRv+A4MQgUi5n4zppJVkTcFIQCfeM3n
yrmuTXI0ttkeoceXAFyr/aQ=
=wyhj
-END PGP SIGNATURE-

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




Re: Starting validation

2006-11-07 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thom,

Thom Burnett wrote:
> With that fixed I can take out the sub class' validate() method and still
> get a set of errors.

That's good, I guess. What do you mean, the subclass's validate method?
I didn't realize that you had multiple levels of validation being performed.

> However, getting errors still depopulate's the form's fields.

That shouldn't happen. Lemmie look at your JSP source again...

Ah. You didn't provide any of the HTML code that contains the 
elements. Could you post a representative sample?

> Again, I can
> fix that by overriding the validate method (calling super) and that's not a
> horrible solution

Yeah... don't do that. You should be able to work directly with the bean
that you already have. No need to go through any acrobatics like this.

Just so I know, what is the superclass for this bean and what does its
super.validate method do that you aren't doing in the subclass?

Come to think of it, why are you overriding the superclass's validate
method in the first place? And... if you are overriding it, why aren't
you calling that superclass method first thing in your overidden method
implementation?

If you have a "base form bean" that contains some utility methods, you
should not have to call super.validate(). On the other hand, if you have
a super class bean that needs its validation done /too/, then you should
do this:

public ActionErrors validate(...)
{
   ActionErrors errors = super.validate(...);

   // Now perform your own validation.

   return errors;
}

> As near as I can see the form is being named and associated correctly but I
> must be missing something.

It looks like validate() is being called, otherwise you wouldn't be
getting error messages. Since your action mapping names the bean /and/
the input attribute is associated with the mapping (i.e. there's no
redirect), that bean (including its invalid input) ought to be available
in the session (as per your 'scope' preference).

Post your JSP code around your  elements and let me have a look.

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

iD8DBQFFUM8a9CaO5/Lv0PARAsyxAJ9YtgRv+A4MQgUi5n4zppJVkTcFIQCfeM3n
yrmuTXI0ttkeoceXAFyr/aQ=
=wyhj
-END PGP SIGNATURE-

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



Re: Starting validation

2006-11-07 Thread Thom Burnett

Chris,

Following your advice, I've now found the proper settings for my resource
file.
With that fixed I can take out the sub class' validate() method and still
get a set of errors.
However, getting errors still depopulate's the form's fields. Again, I can
fix that by overriding the validate method (calling super) and that's not a
horrible solution - since it doesn't cost much work. But I don't think it
should be necessary and am wondering what's not set up right that would
cause that problem.

As near as I can see the form is being named and associated correctly but I
must be missing something.

On 11/7/06, Christopher Schultz <[EMAIL PROTECTED]> wrote:


-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thom,

> struts-config.xml:

This looks good.

>  request.setAttribute("sessionForm", this) ; // If I don't do this
the
> form will be blank after an error.

You really shouldn't have to do this. The form bean in the session will
be called "donorBean" because of the value of the "name" attribute in
your  mapping in struts-config.xml.

>  request.setAttribute("errors", actionErrors) ;

You shouldn't have to do this, either. Struts should be putting this
ActionErrors object into the request for you. This is all you should need:

>  return actionErrors ;


> My validations.xml file - working partially

When you say "partially", you mean that your form is re-displayed when
validation doesn't pass, right? It's just that your errors do not show
up and the form fields are blank. I think your validation is probably
okay, but let's see.

> 

Do all of these properties actually exist in this file:

/WEB-INF/ErrorMessages.properties (this is where you indicated your
message resources were).

I'm not sure what is the "standard" way to do this, but I have my
message resources in my WEB-INF/classes directory, and I specify it like
this:



You might try adding 'null="false"' to see if you start getting messages
like '???en_US.validation.error.firstname???' in your pages. If you get
these messages, it means that struts can't find your error messages, but
they are being properly generated and saved into the request.

>  

This ought to print /something/. My guess is a properties file loading
problem (see above).

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

iD8DBQFFUMCr9CaO5/Lv0PARAg8pAJ0ToTTuxR2wC09xbRLXrGTNKfwa7ACfUhBI
41L+o5dayknOJDxN2PrQOl8=
=T+ly
-END PGP SIGNATURE-

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




Re: Starting validation

2006-11-07 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Thom,

> struts-config.xml:

This looks good.

>  request.setAttribute("sessionForm", this) ; // If I don't do this the
> form will be blank after an error.

You really shouldn't have to do this. The form bean in the session will
be called "donorBean" because of the value of the "name" attribute in
your  mapping in struts-config.xml.

>  request.setAttribute("errors", actionErrors) ;

You shouldn't have to do this, either. Struts should be putting this
ActionErrors object into the request for you. This is all you should need:

>  return actionErrors ;


> My validations.xml file - working partially

When you say "partially", you mean that your form is re-displayed when
validation doesn't pass, right? It's just that your errors do not show
up and the form fields are blank. I think your validation is probably
okay, but let's see.

> 

Do all of these properties actually exist in this file:

/WEB-INF/ErrorMessages.properties (this is where you indicated your
message resources were).

I'm not sure what is the "standard" way to do this, but I have my
message resources in my WEB-INF/classes directory, and I specify it like
this:



You might try adding 'null="false"' to see if you start getting messages
like '???en_US.validation.error.firstname???' in your pages. If you get
these messages, it means that struts can't find your error messages, but
they are being properly generated and saved into the request.

>  

This ought to print /something/. My guess is a properties file loading
problem (see above).

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

iD8DBQFFUMCr9CaO5/Lv0PARAg8pAJ0ToTTuxR2wC09xbRLXrGTNKfwa7ACfUhBI
41L+o5dayknOJDxN2PrQOl8=
=T+ly
-END PGP SIGNATURE-

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



Re: Starting validation

2006-11-07 Thread Thom Burnett

What's now happening is that the validation correctly moves me back to the
jsp specified by input but the form becomes blank (doesn't keep the
information that was entered) and the  returns nothing.

I can sort of get around this by calling validate and adding attributes to
the request but I'm pretty sure that I shouldn't need to do so. So I'm
wondering what's going wrong.

struts-config.xml:


http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";>

 
   
 
 
   
 
 
 
 
 
   
 
 
 
   
 



public class AllDonationInformationFormBean3 extends ValidatorForm {
...
 // This is the addition I seem to need.
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
 ActionErrors actionErrors = super.validate(mapping, request) ;
 request.setAttribute("sessionForm", this) ; // If I don't do this the
form will be blank after an error.
 request.setAttribute("errors", actionErrors) ;
 return actionErrors ;
 }
}

My validations.xml file - working partially


 
   
   
 

  
 

  
  

  
  

  
  

  
  

  
  

  

   
 


Part of my jsp: only the getAttribute type of error shows up. the

 
 Donor
Information
 All errors with Java script
 <%= request.getAttribute("errors") == null ? "No errors" :
request.getAttribute("errors") %>
 All errors with strut tag
 
 Single error report with strut tag
 
 *Indicates required field
 


On 11/7/06, Romu <[EMAIL PROTECTED]> wrote:


validations are linked to xml files:






with name tag, struts will look in validation.xml files to see the rules
etc
, and it wil generates the javascript .

check if u got javascript validation code  in your jsp  ?





2006/11/7, Thom Burnett <[EMAIL PROTECTED]>:
>
> What are common simple mistakes that would prevent validation from
> occuring?
> I've got a simple struts application that runs correctly except that
> validation doesn't occur. The form info is accepted as correct when
> required
> information is missing.
>
> I'm trying to figure out what's missing from my setup or understanding.
>
> The ValidatorForm (my extension) class has appropriate get and set
> functions
> for all fields.
> (The fields are spread over 3 jsp pages, if that matters.)
> I've added the validator plugin to the struts-config, the action mapping
> has
> validate="true" and a valid input path,  added the validation-rules and
> validation.xml file, added the resource properties file with the
standard
> errors (taken from the struts file).
>
> If I write my own validate method in the form bean that validation works
> properly. It's my understanding that if I'm using the validation
> framework,
> I should not have a validate() method in the form.
>
> Am I misunderstanding something? Any ideas what might be setup wrong or
> missing.
>
>




Re: Starting validation

2006-11-07 Thread Romu

validations are linked to xml files:


   

   

with name tag, struts will look in validation.xml files to see the rules etc
, and it wil generates the javascript .

check if u got javascript validation code  in your jsp  ?





2006/11/7, Thom Burnett <[EMAIL PROTECTED]>:


What are common simple mistakes that would prevent validation from
occuring?
I've got a simple struts application that runs correctly except that
validation doesn't occur. The form info is accepted as correct when
required
information is missing.

I'm trying to figure out what's missing from my setup or understanding.

The ValidatorForm (my extension) class has appropriate get and set
functions
for all fields.
(The fields are spread over 3 jsp pages, if that matters.)
I've added the validator plugin to the struts-config, the action mapping
has
validate="true" and a valid input path,  added the validation-rules and
validation.xml file, added the resource properties file with the standard
errors (taken from the struts file).

If I write my own validate method in the form bean that validation works
properly. It's my understanding that if I'm using the validation
framework,
I should not have a validate() method in the form.

Am I misunderstanding something? Any ideas what might be setup wrong or
missing.