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"/>
新闻热点
疑难解答