Re: Iterate over validation errors?

2005-02-27 Thread Erik Weber
Heh, just ignore everything I wrote and listen to Joe.
:)
Erik
Joe Germuska wrote:
 is an iterator through messages, so you can leave the 
HTML out of the resources file:

For the example below, here's how to do it with html:messages instead:







Despite the name, html:messages defaults to looking for ActionMessages 
saved using "saveErrors", not "saveMessages", although you can use the 
"messages='true'" attribute to change that, and you can use other 
attributes to look up an arbitrary ActionMessages saved under any key; 
you can also specify a "property" attribute to filter the list to only 
messages associated with a certain property.

As usual, see the docs for full details, but I prefer html:messages to 
html:errors for this very reason.

Joe

At 5:06 PM -0700 2/27/05, Wendy Smoak wrote:
From: "Adam Jenkins" <[EMAIL PROTECTED]>
Is there a simple way to iterate over all the validation errors.  I
don't want to just do   I want to actually for a
... of all the errors that occured when submitting 
the
page.
Is this possible?  Does anyone have an example I could use?

Do you _really_ want to iterate over the validation errors, or do you 
just want the output to be a bulleted list?  If all you want is the 
 tags around your errors, this works:

ApplicationResources.properties:
  errors.integer={0} must be an integer.
  error.no.userId=User ID does not exist
  error.no.email=No email address on file
  errors.header=
  errors.footer=
somePage.jsp:
  
(The 'error' style just sets the font and turns it red, it's not 
required.)

I'm interested to know if there's a better way to do this-- putting 
markup in the .properties file doesn't seem "right" to me.


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


Re: Iterate over validation errors?

2005-02-27 Thread Erik Weber
Here are a couple of old posts I saved that might help too:

At 5:10 PM -0500 11/8/04, Erik Weber wrote:
Here is a way to do it that works with 1.1:



Username: 

Omitting the "name" attribute in this would have the same effect as 
including it - it's the default.  It's suggested that if you are storing 
messages in your actions using "saveErrors" or "saveMessages" (or 
dealing with validation errors, which are stored as if using 
"saveErrors") then you shouldn't specify "name" literally; instead, you 
can either rely on the default (to get errors) or use the "message" 
attribute with a value of "true" (to get saveMessages messages) or 
"false" (to get errors -- that is, the default behavior).  This helps to 
"encapsulate" the logic of how Struts handles those messages, and makes 
your JSP a bit less verbose also.

Additionally, your code above assumes that the nature of the error 
message is such that you know that the user should be shown the 
"error.username.required" message -- it's probably more flexible to let 
the validation/error handling framework create an ActionMessage object 
with that key itself, and then you would use the messages object; this 
way if any other error should come up (say you add a max-length 
restriction, or forbidden characters), then you don't have to change 
your JSP.

In another response I demonstrated how html:messages can be used to 
achieve the same result you had above, plus this added flexibility I 
mention.

Some people still like to use "html:errors", which predates 
html:messages and which has a slightly different syntax for providing 
any HTML which might "wrap" your messages.  Personally, I prefer 
html:messages.

None of this changed from Struts 1.1 to Struts 1.2.
Hope this helps,
   Joe

Not sure if that tag has changed for 1.2.
Erik
Struts User wrote:
Hello,
Currently, I am using struts validator to validate the fields in my 
ActionForm.
Before I updated to struts 1.2.4, I could add an error this way - 
errors.add(
"username", new ActionError("error.username.required"));

If the validation failed, the error message for username will be
displayed right beside the user name text field if I use Username:
.
Can someone tell me how to display error message beside an input field
using struts validator?
Thanks,
Lee
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

The "other response" Joe mentioned I think was this one:
At 3:49 PM -0600 11/8/04, Struts User wrote:
Hello,
Currently, I am using struts validator to validate the fields in my 
ActionForm.

Before I updated to struts 1.2.4, I could add an error this way - 
errors.add(
"username", new ActionError("error.username.required"));

If the validation failed, the error message for username will be
displayed right beside the user name text field if I use Username:
.
Can someone tell me how to display error message beside an input field
using struts validator?

I've never seen any automatic message placement.  You can access 
messages like this:


html:messages is effectively a combination logic/iterator tag.  If there 
are any "username" messages in the ActionMessages object saved as the 
"errors" messages, the body of html:messages will be evaluated once for 
each, with a scripting variable of type String defined with the name 
specified in the "id" attribute.  You can use c:out or bean:write to 
display this value, wrapped with span, div, or other tags which format 
your messages correctly.

I kind of think someone talked on the list once about making something 
which rendered an HTML "label" tag and which was also "smart" about the 
presence of errors.  I like the idea of something like that in general, 
but wonder if you'd be able to specify something suitably general for 
inclusion in Struts.  Seems like it might be better left for local 
development.

Joe

But I think Niall recently mentioned some improvements in this area in 
1.2.6 . . .

Erik

Adam Jenkins wrote:
Thanks for that, I'll give it a go.  Is there anyway you can accomplish
it without having to put html in the resource bundle?
On Sun, 2005-02-27 at 19:04 -0500, Erik Weber wrote:
 

Last I checked, Struts came configured to do what I think you are asking 
by default.

This is an example of the (Struts 1.1) ApplicationResources.properties file:
#header and footer for form validation error messages
errors.header=input 
error Please resubmit the form after correcting your input to 
meet the following requirement(s):
errors.footer= 

#form validation error messages
#(rendered between header and footer above)
errors.required={0} is required.
errors.minlength={0} cannot contain fewer than {1} characters.
errors.maxlength={0} cannot contain more than {2} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} mu

Re: Iterate over validation errors?

2005-02-27 Thread Joe Germuska
 is an iterator through messages, so you can leave the 
HTML out of the resources file:

For the example below, here's how to do it with html:messages instead:







Despite the name, html:messages defaults to looking for 
ActionMessages saved using "saveErrors", not "saveMessages", although 
you can use the "messages='true'" attribute to change that, and you 
can use other attributes to look up an arbitrary ActionMessages saved 
under any key; you can also specify a "property" attribute to filter 
the list to only messages associated with a certain property.

As usual, see the docs for full details, but I prefer html:messages 
to html:errors for this very reason.

Joe

At 5:06 PM -0700 2/27/05, Wendy Smoak wrote:
From: "Adam Jenkins" <[EMAIL PROTECTED]>
Is there a simple way to iterate over all the validation errors.  I
don't want to just do   I want to actually for a
... of all the errors that occured when submitting the
page.
Is this possible?  Does anyone have an example I could use?
Do you _really_ want to iterate over the validation errors, or do 
you just want the output to be a bulleted list?  If all you want is 
the  tags around your errors, this works:

ApplicationResources.properties:
  errors.integer={0} must be an integer.
  error.no.userId=User ID does not exist
  error.no.email=No email address on file
  errors.header=
  errors.footer=
somePage.jsp:
  
(The 'error' style just sets the font and turns it red, it's not required.)
I'm interested to know if there's a better way to do this-- putting 
markup in the .properties file doesn't seem "right" to me.

--
Joe Germuska
[EMAIL PROTECTED]  
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction"  -The Ex

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


Re: Iterate over validation errors?

2005-02-27 Thread Erik Weber
You could leave errors.header and errors.footer blank, and then wrap 
your html:errors with the markup. Somewhere in the properties file 
you're going to have to at least specify (markup) that you are using a 
bulleted list if I'm not mistaken. There also is a way that you could 
iterate over the individual error messages as you suggest. Then you 
could have no markup in the properties file. See the docs for the 
html:errors and html:messages tags.

Erik
Adam Jenkins wrote:
Thanks for that, I'll give it a go.  Is there anyway you can accomplish
it without having to put html in the resource bundle?
On Sun, 2005-02-27 at 19:04 -0500, Erik Weber wrote:
 

Last I checked, Struts came configured to do what I think you are asking 
by default.

This is an example of the (Struts 1.1) ApplicationResources.properties file:
#header and footer for form validation error messages
errors.header=input 
error Please resubmit the form after correcting your input to 
meet the following requirement(s):
errors.footer= 

#form validation error messages
#(rendered between header and footer above)
errors.required={0} is required.
errors.minlength={0} cannot contain fewer than {1} characters.
errors.maxlength={0} cannot contain more than {2} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is invalid.
#user plugins
errors.twofields={0} must have the same value as {1}.
errors.dateRange={0} is not an acceptable date.
Then a simple  results in the bulleted list of all current 
validation errors, assuming your validation.xml is set up properly so 
that errors are matched with the messages in the properties file.

Hope this helps.
Erik

Adam Jenkins wrote:
   

Hi All,
Is there a simple way to iterate over all the validation errors.  I
don't want to just do   I want to actually for a
... of all the errors that occured when submitting the
page.
Is this possible?  Does anyone have an example I could use?
Cheers
Adam
-
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]
 

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


RE: Iterate over validation errors?

2005-02-27 Thread Joe Hertz
There's one improvement on that method:

errors.prefix=
errors.suffix=

So you don't need to put the markup into each error definition in your
properties file.

If you don't want markup in it at all, you can do something like

 

  
 
  
 


Ted has a good page on this:

http://husted.com/struts/tips/017.html

-Original Message-
From: Wendy Smoak [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 27, 2005 7:06 PM
To: Struts Users Mailing List
Subject: Re: Iterate over validation errors?

From: "Adam Jenkins" <[EMAIL PROTECTED]>
> Is there a simple way to iterate over all the validation errors.  I
> don't want to just do   I want to actually for a
> ... of all the errors that occured when submitting the
> page.
> Is this possible?  Does anyone have an example I could use?

Do you _really_ want to iterate over the validation errors, or do you just 
want the output to be a bulleted list?  If all you want is the  tags

around your errors, this works:

ApplicationResources.properties:
   errors.integer={0} must be an integer.
   error.no.userId=User ID does not exist
   error.no.email=No email address on file
   errors.header=
   errors.footer=

somePage.jsp:
   
(The 'error' style just sets the font and turns it red, it's not required.)

I'm interested to know if there's a better way to do this-- putting markup 
in the .properties file doesn't seem "right" to me.

HTH,
Wendy Smoak







-
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]



RE: Iterate over validation errors?

2005-02-27 Thread Joe Hertz
There's one improvement on that method:

errors.prefix=
errors.suffix=

So you don't need to put the markup into each error definition in your
properties file.

If you don't want markup in it at all, you can do something like

 

  
 
  
 


Ted has a good page on this:

http://husted.com/struts/tips/017.html

-Original Message-
From: Wendy Smoak [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 27, 2005 7:06 PM
To: Struts Users Mailing List
Subject: Re: Iterate over validation errors?

From: "Adam Jenkins" <[EMAIL PROTECTED]>
> Is there a simple way to iterate over all the validation errors.  I
> don't want to just do   I want to actually for a
> ... of all the errors that occured when submitting the
> page.
> Is this possible?  Does anyone have an example I could use?

Do you _really_ want to iterate over the validation errors, or do you just 
want the output to be a bulleted list?  If all you want is the  tags

around your errors, this works:

ApplicationResources.properties:
   errors.integer={0} must be an integer.
   error.no.userId=User ID does not exist
   error.no.email=No email address on file
   errors.header=
   errors.footer=

somePage.jsp:
   
(The 'error' style just sets the font and turns it red, it's not required.)

I'm interested to know if there's a better way to do this-- putting markup 
in the .properties file doesn't seem "right" to me.

HTH,
Wendy Smoak







-
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]



Re: Iterate over validation errors?

2005-02-27 Thread Adam Jenkins
Thanks for that, I'll give it a go.  Is there anyway you can accomplish
it without having to put html in the resource bundle?

On Sun, 2005-02-27 at 19:04 -0500, Erik Weber wrote:
> Last I checked, Struts came configured to do what I think you are asking 
> by default.
> 
> This is an example of the (Struts 1.1) ApplicationResources.properties file:
> 
> #header and footer for form validation error messages
> errors.header= cellpadding="0">input 
> error  align="left">Please resubmit the form after correcting your input to 
> meet the following requirement(s):
> errors.footer= 
> 
> 
> #form validation error messages
> #(rendered between header and footer above)
> errors.required={0} is required.
> errors.minlength={0} cannot contain fewer than {1} characters.
> errors.maxlength={0} cannot contain more than {2} characters.
> errors.invalid={0} is invalid.
> errors.byte={0} must be an byte.
> errors.short={0} must be an short.
> errors.integer={0} must be an integer.
> errors.long={0} must be an long.
> errors.float={0} must be an float.
> errors.double={0} must be an double.
> errors.date={0} is not a date.
> errors.range={0} is not in the range {1} through {2}.
> errors.creditcard={0} is not a valid credit card number.
> errors.email={0} is invalid.
> #user plugins
> errors.twofields={0} must have the same value as {1}.
> errors.dateRange={0} is not an acceptable date.
> 
> 
> Then a simple  results in the bulleted list of all current 
> validation errors, assuming your validation.xml is set up properly so 
> that errors are matched with the messages in the properties file.
> 
> Hope this helps.
> 
> Erik
> 
> 
> 
> Adam Jenkins wrote:
> 
> >Hi All,
> >
> >Is there a simple way to iterate over all the validation errors.  I
> >don't want to just do   I want to actually for a
> >... of all the errors that occured when submitting the
> >page.
> >
> >Is this possible?  Does anyone have an example I could use?
> >
> >Cheers
> >Adam
> >
> >
> >-
> >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]



Re: Iterate over validation errors?

2005-02-27 Thread Wendy Smoak
From: "Adam Jenkins" <[EMAIL PROTECTED]>
Is there a simple way to iterate over all the validation errors.  I
don't want to just do   I want to actually for a
... of all the errors that occured when submitting the
page.
Is this possible?  Does anyone have an example I could use?
Do you _really_ want to iterate over the validation errors, or do you just 
want the output to be a bulleted list?  If all you want is the  tags 
around your errors, this works:

ApplicationResources.properties:
  errors.integer={0} must be an integer.
  error.no.userId=User ID does not exist
  error.no.email=No email address on file
  errors.header=
  errors.footer=
somePage.jsp:
  
(The 'error' style just sets the font and turns it red, it's not required.)
I'm interested to know if there's a better way to do this-- putting markup 
in the .properties file doesn't seem "right" to me.

HTH,
Wendy Smoak



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


Re: Iterate over validation errors?

2005-02-27 Thread Erik Weber
Last I checked, Struts came configured to do what I think you are asking 
by default.

This is an example of the (Struts 1.1) ApplicationResources.properties file:
#header and footer for form validation error messages
errors.header=input 
error Please resubmit the form after correcting your input to 
meet the following requirement(s):
errors.footer= 

#form validation error messages
#(rendered between header and footer above)
errors.required={0} is required.
errors.minlength={0} cannot contain fewer than {1} characters.
errors.maxlength={0} cannot contain more than {2} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.
errors.date={0} is not a date.
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is invalid.
#user plugins
errors.twofields={0} must have the same value as {1}.
errors.dateRange={0} is not an acceptable date.
Then a simple  results in the bulleted list of all current 
validation errors, assuming your validation.xml is set up properly so 
that errors are matched with the messages in the properties file.

Hope this helps.
Erik

Adam Jenkins wrote:
Hi All,
Is there a simple way to iterate over all the validation errors.  I
don't want to just do   I want to actually for a
... of all the errors that occured when submitting the
page.
Is this possible?  Does anyone have an example I could use?
Cheers
Adam
-
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]


Iterate over validation errors?

2005-02-27 Thread Adam Jenkins
Hi All,

Is there a simple way to iterate over all the validation errors.  I
don't want to just do   I want to actually for a
... of all the errors that occured when submitting the
page.

Is this possible?  Does anyone have an example I could use?

Cheers
Adam


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