Monday, June 2, 2014

JSF Validation, custom validator message not working

I tried to make a simple validation on a simple input text that passes the value to an integer .. added a validation message just to make sure the user does not insert a character .. added a custom validator message to tell the user "Please enter a digit". but the customized message never showed, instead I always go the default JSF validation message for an integer.

For this xhtml,


<h:inputText value="#{reconciliations.amount}" validatorMessage="Please enter a valid digit number" class="defaultText" name="idType" id="amountTxt" >
				<f:validateRegex pattern="[0-9]*"></f:validateRegex>
				</h:inputText>

Here is the code that DID NOT work and I always got this error message:
viewReconciliation:amountTxt: 'a' must be a number between -2147483648 and 2147483647 Example: 9346

My Managed Bean:


private int amount;

	public int getAmount() {
		return amount;
	}


	public void setAmount(int amount) {
		this.amount = amount;
	}

Here is the code that did work
Now I get the custom message I wanted.
Please enter a valid digit number
My Managed Bean:

private String amount;

	public String getAmount() {
		return amount;
	}


	public void setAmount(String amount) {
		this.amount = amount;
	}

No comments:

Post a Comment