File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes html:error to print specific error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:error to print specific error" Watch "html:error to print specific error" New topic
Author

html:error to print specific error

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Dear All
I have a requirement that I need to print a specific error message which also displays the entered values as a part of error message

e.g. I enter two in a text field and message shall appear

"The value two is invalid"

I know that html:error tag reads message from Application.Resources properties file where we only can specify generic message but here requirement is that I need to throw data also with message

If any Guru can give me some cue that will be of great help

Thanks in advance
:roll:


SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
Yeah....you can pass text value as a argument in ActionError. i am giving you a code line ...not sure ...but check it out...


and in your properties file put below line...
errors.textboxerror= The value {0} is invalid

hope it works...i
or you can use Validator framewors....it works....


Milan.<br />I can because I think I can...
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
This question gets asked enough that I am sure that somebody has found a "solution". To me it just seems like a bad requirement. The basic idea is that your form shows the fields: say Name, Age, and Weight. If the user enters an invalid value in Weight field the user sees the message "Weight is invalid", or "Weight is not a valid whole number". The user looks at the Weight field and sees that they entered the text "two" so they correct it. If the message just said "The value two is invalid" and they entered "two" in multiple fields they have no idea which one is invalid.

- Brent
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
You are right Brent
This shall not be an ideal way to display wrongly entered values as part of error messages but we don't control these business users and have to adhrere to what they demand

Thanks a bunch Milan for giving me a hint
It works now
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Milan: How could you do this using the Validator framework?

- Brent
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
Originally posted by Brent Sterling:
Milan: How could you do this using the Validator framework?

- Brent


first replace "ActionForm" with "ValidatorForm" in your form bean.
now suppose your text box name is "firstName" and you want to make it mandatory. refer below lines...


check it out.....
[ February 15, 2007: Message edited by: Milan Jagatiya ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Milan: I understand how to use the Validator framework. The original poster wanted to have a message like "The value two is invalid". It seems like that example would just be able to print a message like "The field First Name is invalid". As far as I know the Validator framework does not support including the value that the user entered into the validation message. Please correct me if I am wrong.

Gaurav: I would also suggest that using text like "is invalid" is not a good idea. It would be much better if you could show messages that would mean something to the users. Messages like "X is not a valid phone number", "Y is not a valid decimal number", or "Z does not meet the password requirements".

- Brent
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Dear Brent

I agree with you as it seems we can't give specific wrong values entered using validator framework
As far as my case was concerned requirment was that in a text area a comma,seperated list of domains are entered and error message should specifically tell which of the entered values are blacklisted
Thanks
Gaurav
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
Originally posted by Brent Sterling:
Milan: I understand how to use the Validator framework. The original poster wanted to have a message like "The value two is invalid". It seems like that example would just be able to print a message like "The field First Name is invalid". As far as I know the Validator framework does not support including the value that the user entered into the validation message. Please correct me if I am wrong.

- Brent

Yeah you are right Brent, The Validator framework does not support including the value that the user entered into the validation message as Gaurav wants but only the specific field name. and that is the right way i think..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:error to print specific error