• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Combo box internationalization

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

I hava a combo Box in JSP. and I populate it by action form
<html:select property="l">
<html ptions name="languageType"/>
</html:select>

But now values in options are in english. But I want to put internationlization effect on them means options should display in the languge according to locale
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have a couple of different options here.

1-If the data for the dropdown box is coming from a database, you are going to have to store the option descriptions in each language in the database with the locale or language as part of the key. Then, in the Action class that forwards to this JSP, get the locale of the client by calling super.getLocale(). From this, you can tell what language the client is using and populate the list used by <html ptions> from the database in the appropriate language.

2-If the options are not coming from a database, but you just want them displayed in the appropriate laguage, use the <html ption key="xxx"> tag for each option. The text for the option will then be taken from your ApplicationResources bundle and will be in the appropriate language
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just thought of a third option:

You could put the value and the message key in the database and define each message key in each of the languages in your resource bundle. In your JSP, you could then iterate through the list of values and keys obtained from the database and specify something like this:

<html:select property="selected" >
<c:forEach var="option" items="options">
<option key ="${option.messageKey}" value="${option.value}" />
</c:forEach>
</html:select>

to display each option in the local language.

The above code assumes you're using the strut-el version of the tag libraries.
 
pax smith
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using the third option But I am getting the following error


Java


HashMap languagesType= new HashMap ();
languagesType.put("top.property.link" ,"1");
languagesType.put("top.property.unlink","2");
languagesType.put("top.property.item","3");
request.setAttribute("languageType",languagesType);

JSP
<html:select property="language">
<c:forEach var="option" items="languageType">
<option key ="${option.messageKey}" value="${option.value}" />
</c:forEach>
</html:select>

Error


org.apache.jasper.JasperException: <h3>Validation error messages from TagLibraryValidator for c</h3><p>null: org.xml.sax.SAXParseException: Attribute "style" was already specified for element "html:select".</p>
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:411)
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use <html:select>, you must also use <html:option> instead of just <option>.
[ January 26, 2006: Message edited by: Merrill Higginson ]
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic