public class stringconverter implements converter {
 public object getasobject(facescontext context, uicomponent component,
   string newvalues) throws converterexception {
  string newstr = "";
  if (newvalues == null) {
   newvalues = "";
  }
  byte[] byte1 = null;
  try {
   byte1 = newvalues.getbytes("iso-8859-1");
   newstr = new string(byte1, "gb2312");
   uiinput input=(uiinput)component;//
   input.setsubmittedvalue(newstr);
  } catch (unsupportedencodingexception e) {
   e.printstacktrace();
  }
return newstr;
}
 public string getasstring(facescontext context, uicomponent component,
   object values) throws converterexception { 
  return (string) values;
 }
}
2、注冊轉換器
faces-config.xml片段
<converter>
  <converter-id>util.stringconverter</converter-id>
  <converter-class>util.stringconverter</converter-class>
</converter>
3、在頁面使用轉換器
<h:inputtext id="account" value="#{util.account}" required="true" styleclass="input" > 
 <f:converter converterid="utilstringconverter"/>
新聞熱點
疑難解答