简体   繁体   English

如何使用JSF阻止h:inputText上的负数

[英]How to block negative numbers on h:inputText with JSF

I´m using jsf to build a form, and I have this kind of inputtext: 我使用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>

and I have to block negative numbers and give a message to user inline that number is forbidden, how is working when the user types a invalid number on input.. 我必须阻止负数并向用户发送一条消息,内联该号码是禁止的,当用户在输入上输入无效数字时如何工作..

Does someone know how I can do that? 有人知道我该怎么做吗?

Use <f:validateLongRange> with a minimum of 0 . 使用<f:validateLongRange> minimum0

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

The default validation message is: 默认验证消息是:

Validation Error: Value is less than allowable minimum of '0' 验证错误:值小于允许的最小值“0”

Any custom validation message can be set via validatorMessage the same way as you did for converterMessage . 可以通过validatorMessage以与converterMessage相同的方式设置任何自定义验证消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM