It's not a secret anymore!*
The moose likes Struts and the fly likes Combo box internationalization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Combo box internationalization" Watch "Combo box internationalization" New topic
Author

Combo box internationalization

pax smith
Ranch Hand

Joined: Dec 13, 2005
Posts: 45
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

Joined: Feb 15, 2005
Posts: 4864
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
Consultant, Sima Solutions
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Dec 13, 2005
Posts: 45
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

Joined: Feb 15, 2005
Posts: 4864
When you use <html:select>, you must also use <htmlption> instead of just <option>.
[ January 26, 2006: Message edited by: Merrill Higginson ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Combo box internationalization
 
Similar Threads
Combo box options based on another combo box option selected
Setting a preselected value in a combo
on
Exception thrown by getter for property
Map with html:optionCollection