• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Display actual value in validations

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I wanted to display the actual value that is causing a Struts validator to fail, how would I do this? For example, if I use the depends="email" rule, and I have:

errors.email={0} is not a valid email address

as my error message resource, how can I pass the actual text value into the message?

<arg0 key=" ...? " resource="false"/> but what should go into to key? ${field.value} ?

Thanks.
 
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
validator cannot be configured to display the actual value. You may have to generate the javascript and modify it to show the value. html:javascript doc
says


The dynamicJavascript and staticJavascript attributes default to true, but if dynamicJavascript is set to true and staticJavascript is set to false then only the dynamic JavaScript will be rendered. If dynamicJavascript is set to false and staticJavascript is set to true then only the static JavaScript will be rendered which can then be put in separate JSP page so the browser can cache the static JavaScript.

 
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no that's not correct. it works, at least on my machine :-)





you need to use {1} as the argument, will not work with {0}

cheers,
jan
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan, you overlooked the fact that 5000 is predefined constant. It's not the value user entered.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Purushothaman, you are right :-)
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question comes up fairly often. I would say that the validation framework should be extended to support this behavior, but I do not see the value.

The basic idea is that you have a form with fields...say Name and Email Address. If validation fails then the page is redisplayed with the values that the user entered. The user would then see validation messages like "Name is required" or "Email Address is not a valid email address". Putting the email address that the user entered into the validation message does not seem to add much value because the user can look at the Email Address field and see the value that was invalid. Also if you had multiple email address fields on your page the user would have to figure out which field is invalid.

My $0.02.

- Brent
 
Men call me Jim. Women look past me to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic