Solved

Error messages for Struts validation

Posted on 2004-08-05
3
180 Views
Last Modified: 2010-04-01
I've got a question that I don't think is possible, but I want to make sure!

I have a form field that has a maxlength dependent on other options.  I have written my own validator to check that the length is valid - ( dependent on these other options) , and that works just fine.

Now to take it one step further, it would be ideal if I could have the error message that I have stored from ApplicationResources.properties  be chosen depending on these other options....

So instead of having a generic message: "The length is invalid" or something like that, it could actually say what the length required is.  I can't use the actual maxlength validator that does this, because of the way the fields are being used by multiple name codes.  

So is there a way to choose a different error message from within the validator class, or is it only possible to have one error message per validator, as entered in the validator-rules.xml?

Thanks!
Matt
0
Comment
Question by:Cluniac
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 200 total points
ID: 11727428
If you write your own ActionForm class, and override the validate() method, then you can pass whatever message you want out of ApplicationResources.properties...

http://publib.boulder.ibm.com/infocenter/wsphelp/index.jsp?topic=/com.ibm.etools.struts.doc/html/rstruse0004.htm

has an example of a validate method

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With the rapid rise in mobile usage, mobile devices are here to stay and have become an integral part of doing business. Here are 9 great apps for your BYOD environment.
Knowledge base software has turned out to be a quite reliable method for storing information, promoting collaborative work and for sharing valuable input and solutions.However, some organizations are trying to develop a knowledge base that works wit…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now