• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Struts2 validation localization problem

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i have a problem with localization and the error output.

lets say i have a message defined like this

and a validator like this

if this fails Im going to get an error message like

"requestDate is required"

but what I want is

"Request Date is required".

in struts1 using the commons validator I was able to define a parameter which would be used for display purposes on error messages...how can i achieve that in struts2 validation framework??
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All OGNL is available in resource strings, allowing all sorts of madness. If I remember I'll cut-and-paste an example from the book where I cover this.
 
Raymond Holguin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks david, unless you can suggest a better solution i came up with this idea to just do something like this



and just rinse and repeat for all my fields. i dont particularly like this method...i dont know why but its looks messy but i gotta work with what i have.


EDIT: or better yet maybe something like this...i like this a little better
EDIT#2: Below DOES NOT WORK, but leaving it here for reference!!


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't that mean you're defining the label in two places though?
 
Raymond Holguin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
im not sure what you are referring too david. But either way...the second option was a no go as the validator does not except params that are not defined in that type of validator. so i was not able to create a custom "label" param.

as for my first solution if your referring to the fact I define a string
form.requestDate.label = Request Date

and then call that string like this
<message>${getText("form.requestDate.label")} ${getText("required")}</message>

then i suppose it could be defining it twice since i might as well just explicitly say "Request Date" in the <message>, but the fact is that there are many instances in the app where the same field is used throughout many different forms. so defining it once makes it reusable no matter what form or page and its easy just to update the label field once in case i need too instead of searching through multiple validation files to update that field.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was talking about the second one (which I didn't actually think would work, but misinterpreted your message as meaning it did).
 
Raymond Holguin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yea that was my bad, i know that its struts1 you could arbitrarily define any params you want and i assumed you could do the same in struts2 so i suggested #2 w/out even testing it. wont make that mistake again!! ill edit my post to clarify it doesn't work!!
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Raymond Holguin

Did you solve the problem ?

I have same problem now could you please help me?

a sample or a link
 
Raymond Holguin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For me i just stuck with my orignal solution



This allowed me some flexibility for the scenarios where I use the same label multiple times throughout my app then its standardized and defined in one location and all i have to do is just reference the label string. And if i want to change how "Request Date" is displayed i only have to change it in one location instead of several.
 
mehdi chorsi
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thank you so much it is good solution

I've done and It's work
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic