java - How to parse the string with some UTF8 characters in the html:optionCollection in struts using LocalValueBean? -


i have read resource file , created dropdownlist using html:optionscollection. unable parse utf8 string showing in dropdown selection in screenshot. should parse français (canada)

showing in screenshot : enter image description here

following sample code

jsp code :

<html:select property="locale" onchange="refreshpage(this.value)">                                 <html:optionscollection property="dropdownlist"/> </html:select> 

action form bean class

public void setdropdownlist(collection dropdownlist){                 this.dropdownlist = dropdownlist;         }   public collection getdropdownlist(){                 if(dropdownlist == null){                         dropdownlist = new vector(10);                         locale availablelanguages[] = daofactory.getconfigurationdao().getavailablelanguages();                         properties properties = loadproperties(locale.english);                          for(int i=0 ; i<availablelanguages.length ; i++){                                 string localenamekey = "com.web.ui.localename." + availablelanguages[i].tostring();                                 string value = availablelanguages[i].tostring();                                 string key = properties.getproperty(localenamekey);                                 dropdownlist.add(new labelvaluebean(key,value));                         }                         log.debug("size of dropdown :: "+dropdownlist.size());                 }                 return dropdownlist;         }  private properties loadproperties(locale locale) {                 try {                         inputstream inputstream = null;                          inputstream = loginform.class                                         .getresourceasstream("/resources/application_"                                                         + locale.getlanguage() + "_" + locale.getcountry()                                                         + ".properties");                         if (inputstream == null) {                                 inputstream = loginform.class                                                 .getresourceasstream("/resources/application.properties");                         }                         if (inputstream == null) {                                 throw new illegalstateexception(                                                 "unable load application properties.");                         }                          //bufferedreader buffread = new bufferedreader(new inputstreamreader(inputstream));                         properties p = new properties();                         p.load(inputstream);                         return p;                 } catch (ioexception e) {                         throw new illegalstateexception(                                         "was not able load application properties.");                 }         } 

any appreciated.

jsp code scriptlets :

<html:select property="locale" onchange="refreshandsetvalues(this.value)">                <% locale availablelanguages[] = daofactory.getconfigurationdao().getavailablelanguages();                   (int i=0; i<availablelanguages.length; i++) {                       string localenamekey = "com.web.gui.localename." + availablelanguages[i].tostring(); %>                       <html:option value="<%= availablelanguages[i].tostring() %>"                             key="<%= localenamekey %>"/>                <% }%>               </html:select> 

scriptlet code read properties file , parse strings successfully.

properties file

com.web.ui.locale=language com.web.ui.localename.en_us=english com.web.ui.localename.fr_ca=fran&ccedil;ais (canada) com.web.ui.localename.fr_ca.decoded,français (canada) com.web.ui.localename.fr_fr=français (france), com.web.ui.localename.nl_nl=nederlands com.web.ui.localename.es_419=español (américa latina) com.web.ui.localename.es_es=español (castellano) com.web.ui.localename.de_de=deutsch 

well, problem right there in properties file:

com.web.ui.localename.fr_ca=fran&ccedil;ais (canada) 

compared to:

com.web.ui.localename.fr_fr=français (france), 

since have escape in file, , jsp escapes escape, should remove escape , copy word france line.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -