This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic