Question

I´m using jsf to build a form, and I have this kind of inputtext:

<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?

Était-ce utile?

La solution

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

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

The default validation message is:

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

Any custom validation message can be set via validatorMessage the same way as you did for converterMessage.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top