aspose file tools*
The moose likes Struts and the fly likes validation: replacing {0} with the value the user entered Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validation: replacing {0} with the value the user entered" Watch "validation: replacing {0} with the value the user entered" New topic
Author

validation: replacing {0} with the value the user entered

Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
in my validation.xml, I have the following:

<form-validation>
<formset>
<form name="VerifyStudentForm">
<field property="birthDate" depends="date">
<arg0 key="[put what the user entered here]" />
</field>
</form>
</formset>
</form-validation>

the default message resource is:
"errors.date={0} is not a date."

If the user enters "02/31/1977" the validation will fail. I would like the error message to read:
"02/31/1977 is not a date"

How do I get the value the user entered to replace {0}?

Jason Berk
Jason Berk
Ranch Hand

Joined: May 03, 2006
Posts: 41
anybody?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I am not sure. The basic idea is that you would put the label of the field in the message. That way the user would see a message saying "Begin Date is not a valid date". This seems like it would be pretty easy if you implemented the validate method yourself in Java code, but I don't know how to use a dynamic value using the validation framework.

BTW, it may not even be a useful thing to do. When a validation error triggers, the user can look at the value in the "Begin Date" field so I am not sure that adding this value to the message really adds value.

- Brent
Vani Bandargal
Ranch Hand

Joined: Oct 06, 2005
Posts: 82
I don't if we can do something in Validation.xml but in Action Class method or Action form(If you have created a .java file as opposed to defining in Struts.config,
you can try this:

ActionMessages messages=new ActionMessages("errors.date",userEnteredValue) ;
saveErrors(req, messages);

[ May 19, 2006: Message edited by: Vani D Bandargal ]
[ May 19, 2006: Message edited by: Vani D Bandargal ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validation: replacing {0} with the value the user entered