File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validator Message Arguments" Watch "Struts Validator Message Arguments" New topic

Struts Validator Message Arguments

Dan Ludwig

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" />

..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?


I agree. Here's the link:
subject: Struts Validator Message Arguments
jQuery in Action, 3rd edition