validation - 如何在 h :inputText with JSF 上阻止负数

标签 validation jsf-2 message negative-number

我正在使用 jsf 来构建一个表单,我有这种输入文本:

<div class="profile-info-row">
    <div class="profile-info-name">Promoção:</div>
    <div class="profile-info-value">
        <span class="input-icon input-icon-right">
            <h:inputText id="promocao" class="input-medium"
                value="#{itemController.itemPreco.promocao}"
                converterMessage="Valor inválido. (Ex.: 0.00)">
                <f:convertNumber locale="pt"/>
                <f:ajax event="change" render="promocaoMensagem"/>
            </h:inputText>
        </span>
        <div class="help-inline mensagemErro">
            <h:message for="promocao" id="promocaoMensagem"/>
        </div>
    </div> 
</div>

我必须阻止负数并向用户内联发送一条消息,该号码被禁止,当用户在输入中输入无效数字时如何工作..

有人知道我该怎么做吗?

最佳答案

使用 <f:validateLongRange> minimum0 .

<h:inputText ...>
    <f:validateLongRange minimum="0" />
</h:inputText>

默认验证消息是:

Validation Error: Value is less than allowable minimum of '0'



任何自定义验证消息都可以通过 validatorMessage 设置与您对 converterMessage 所做的相同.

关于validation - 如何在 h :inputText with JSF 上阻止负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18983985/

相关文章:

java - 使用带有 javascript 的托管 bean 来创建元素

python - Python 每秒增加消息数

c++ - C++ sdi 应用程序中的 Static_cast 编译器错误

php - Symfony 表单字段即使有错误也有效?

ruby-on-rails - rails : list accepted values of "validates :inclusion" field

javascript - 更改 Javascript 中的数字捕获以接受点

delphi - COM接口(interface)总是用 "catastrophic failure"屏蔽异常消息

apache-flex - 验证复杂 Flex 表单的最佳方法是什么?

java - 向 JSF 2 数据表动态添加行组件

jsf - java.lang.NoClassDefFoundError : javax/el/ELResolver when running SimpleHelloByEnteringName JSF example 错误