File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to avoid question marks in internationalization using JSTL fmt

 
Babji Reddy
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JSTL when we use a tag like
<fmt:message key="my.pending.key"/>

And if the resource bundle does not have an entry for that key, the HTML output will look like ???my.pending.key???

I know this helps in identifying the missing entries in the resource bundle and hence one can go and add them. But is there a way to tell JSTL not to render the question marks and just render the value as my.pending.key

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSTL Spec describes all the capabilities of the <fmt:message> tag, and customizing the error output is not one of them.

I personally cannot think of any reason to do so. Are you trying to provide some sort of customer-visible default?
 
Babji Reddy
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a prototype, I need to use a run time translator service provided by the customer, and for certain strings that have capitalized strings the translated value remains same and the service does not add such strings to the bundle. The expected behavior is that if you don't find the translation display the source as is.

I have discussed with the customer to add the strings to bundle even if there is no translation, but in turn I was asked to see if I can render the original text as is. And JSTL adds the question marks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah -- lazy client syndrome.

One approach you might take is to create a tag file that would handle this for you. The tag file could use the <fmt:message> tag with the var attribute to assign the value to a scope variable. You can check the variable, and if needed, use the key directly rather than the error output.
 
Babji Reddy
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your suggestion seems much elegant than the if/else check that I am doing in JSTL. These if/else are making my JSTL tags messy
Can you please elaborate with a bit more if you do not mind.
How would such custom tag syntax looks like? and how will the code behind the tag looks like?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing tag files is easy. Look up a tutorial or in the JSP Spec.

Within the tag file, assuming that it is defined with an attribute named key, you can use:This will write the result of the lookup into scoped variable value, which you can then test.
 
Babji Reddy
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
worked like a charm! another happy client...
Thank you..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Vinay mailtovinay
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

We have a similar requirement , can someone explain in detail what exactly needs to be done to hide ???.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with the approach already described?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic