This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
anybody?
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic