2016-06-22 33 views
0

我試圖強制在輸入內使用逗號而不是點。Howto強制在primefaces inputText中使用逗號而不是點?

<p:inputText id="interes" value="#{myBean.interes}" label="interes" required="true" locale="es"> 
    <f:convertNumber pattern="##,##" type="currency" currencySymbol="" locale="es" /> 
</p:inputText> 

現在,當我寫了一些這樣的:5.6爲56

但是我希望其他的行爲,它會自動設置:

  • 將其轉換爲5,6(逗號,而不是點)
  • 顯示驗證錯誤

是否有可能只白衣primefaces屬性或者我應該使用JavaScript?

在此先感謝。

回答

1

我建議使用偵聽到輸入文本是這樣的:

HTML代碼:

<p:inputText id="interes" value="#{myBean.interes}" label="interes" required="true" locale="es"> 
    <p:ajax event="change" update="interes" listener="#{myBean.changeFormat}" /> 
</p:inputText> 

您changeFormat方法將做的工作

-1

您駕駛室使用onblur="this.value = this.value.replace('.',',')"輸入文本中。但它取代了第一次出現。在字符串中。我不確定你會得到什麼豆

相關問題