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

struts action messages - placeholder replacement

 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

This question is regarding struts error handling and using placeholders for displaying custom messages.

Currently my application resources properties file has messages something like this
----
errors.range={0} is not in the range {1} through {2}.
----
Now when we construct the action message from java code for the same, the placeholder string {0} in the message is replaced by the first runtime argument, {1} is replaced by the second argument, and so on for the mentioned key (errors.range) in the order we provide the replacement values.
Rather than this, I want to couple the placeholder in application resource properties keys with the values we provide from java code.
To give a hypothetical example say the message in french evaluates to something like this
errors.range={1} is not in the range {0} through {2}. or in japanese its like this
errors.range={2} is not in the range {1} through {0}.
(not the exact syntax just trying to elaborate)

I want the code to tackle such situations in a generic fashion or should i resort to the above approach of semantically adjusting the placeholders based on the language. The placeholder values are fetched from the external system to which we communicate.

Do post your thoughts on the same.

Thanks
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in English it would be:
{0} must be greater than {1}

...and in Yoda-ese it would be:
greater than {1} must {0} be

Attempted Star Wars humor aside...I don't see the issue with the solution you show. What shortcomings are there with shifting around the numbers?

- Brent
 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Brent.

Sorry for not elaborating enough.
As I had mentioned in my post "The placeholder values are fetched from the external system to which we communicate."
This external system is a web service and there is no guaranteed order on parameters it return as part of xml response. So the web service may return <param name="category">Travel</param>
<param name="country">US</param>

In the properties file I want to have placeholders like "category" and "country" and set the resource bundle in a name value fashion and substitute the actual error message accordingly.

Please do post you thoughts on the same.



Regards
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic