File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combo box internationalization

 
pax smith
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you use <html:select>, you must also use <htmlption> instead of just <option>.
[ January 26, 2006: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic