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 Struts Validator Message Arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validator Message Arguments" Watch "Struts Validator Message Arguments" New topic
Author

Struts Validator Message Arguments

Dan Ludwig
Greenhorn

Joined: Jun 05, 2004
Posts: 18
I think it's great that I can compose validation failure messages using a resource properties file, passing in different resource keys as arguments like so:

<field property="fieldname" depends="required">
<msg name="reqmsg" key="form.add.errors.fieldname.required" />
<arg0 key="form.fieldname.display" />
</field>

..Which has a properties resource that results in the message:

<span class="error-field">Field Name</span> is required.

So, what if I want to use a runtime value as a message argument? Is that possible with the Struts Validator? How is it accomplished? For example, my target message would be something like:

The <span class="error-field">Username</span> <span class="error-value">root</span> is already taken by another user. Please choose a different <span class="error-field">Username</span>.

... The message properties would look something like:

user.add.errors.username.taken=The <span class="error-field">{0}</span> <span class="error-value">{1}</span> is already taken by another user. Please choose a different <span class="error-field">{0}</span>.

But, I can't find any documentation on how to configure validation.xml to pass the argument in from a FormBean property. Am I chasing my tail, or is this possible?

Thanks,

Dan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts Validator Message Arguments