我需要一个输入组件来只接受数字,如[0-9]
. 我通过服务器端转换/验证实现了这一点:
<h:inputText ... converter="javax.faces.Integer" />
但是,它仍然允许在 UI 中输入其他字符。在活动期间如何防止这种情况keypress
发生?
<h:inputText ... converter="javax.faces.Integer" onkeypress="...help?" />
我需要一个输入组件来只接受数字,如[0-9]
. 我通过服务器端转换/验证实现了这一点:
<h:inputText ... converter="javax.faces.Integer" />
但是,它仍然允许在 UI 中输入其他字符。在活动期间如何防止这种情况keypress
发生?
<h:inputText ... converter="javax.faces.Integer" onkeypress="...help?" />
尝试这个
<h:inputText id="presentReading" styleClass="labelfont" label="Present Reading" converter="javax.faces.Integer"value="#{FuelFilling1.presentReading}" maxlength="10">
<f:validateLongRange minimum="1" maximum="10"/>
</h:inputText>
或者,您可以使用 JQuery 或 Javascript 在客户端的按键上进行验证。你可以使用 Jquery 吗?
我建议坚持使用 jsf 验证。
<f:convertNumber integerOnly="true" type="number" />
如果您不想将表单提交给获取响应,则可以使用 ajax 进行实时验证。可以使用 javascript/jQuery 进行按键验证,但除非您有充分的理由这样做,否则会很痛苦。