在下面的表格中,我們嘗試將用戶的輸入返回給JSF的h:inputText
或PrimeFaces的p:inputText
。 當輸入非拉丁字符(日文,希伯來文等)時,我們會遇到奇怪的行爲:第一次提交JSF的h:inputText錯誤的字符集
第一次請求我們得到無法識別的字符集,但是在第二次請求時 - 我們得到了正確的結果。
輸入/輸出實例(第一次只能運行):
日本: 輸入=日 輸出=æ¥
希伯來語: 輸入=א 輸出=×
JSF:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<body>
<h:form>
<h:outputLabel value="Name:"/>
<h:inputText value="#{newTestController.registeredCustomerFirstName}"/>
<h:commandButton value="Continue" action="#{newTestController.RegisteredNewCustomer(actionEvent)}"/>
</h:form>
</body>
</html>
輔助Bean:
@ManagedBean(name = "newTestController")
@SessionScoped
public class NewTestController {
private String registeredCustomerFirstName;
public String getRegisteredCustomerFirstName() {
return registeredCustomerFirstName;
}
public void setRegisteredCustomerFirstName(String registeredCustomerFirstName) {
this.registeredCustomerFirstName = registeredCustomerFirstName;
}
public void RegisteredNewCustomer(ActionEvent actionEvent) throws Exception {
}
}
'h:inputText'來自標準的JSF。你不是指'p:inputText'嗎?至於這個問題,你是如何以及在哪裏確認角色是mojibake?在打印日誌並閱讀時?或者在提交後檢查重新顯示的表單時? – BalusC 2012-03-10 16:47:30
對不起。這在'p:inputText'和'h:input'上都會發生,所以它可能與JSF相關,而不是相關的。至於這個問題:在'getRegisteredCustomerFirstName()'上重新顯示,記錄和設置斷點時就可以看到它。 – Daniel 2012-03-11 05:05:22
我有一個沒有解釋的解決方案。對於glassfish,請在glassfish-web.xml中添加。儘管如此,爲什麼它只是第一次失敗呢? –
Daniel
2012-03-11 13:00:30