• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jason Berk
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody?
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic