Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
I hired a bunch of ninjas. The fridge is empty, but I can't find them to tell them the mission.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic