tags:

views:

26

answers:

2

I need to create one textfield custom components which accepts only credit card number like following format xxxx-xxxx-xxxx-xxxx and it should accept only number. so how can i do that i know the simple steps of how to create a custom components. and i am using jsf 1.2 version

A: 

The simplest method is to write a custom Validator.

  • Create a new class that implements the javax.faces.validator.Validator interface and throws appropriate javax.faces.validator.ValidatorException when the input fails validation.
  • Register your validator in the faces-config.xml file (under WEB-INF)
  • Add an input text (h:inputText) tag to your page and specify the validator using the f:validator tag.

Your custom validator will automatically be invoked with the normal JSF lifecycle when the form is posted.

dannywartnaby
@dannywartnaby but i need to create a custom component that's requirement
vinod
Are you using Facelets? Or just plain ole JSF?
dannywartnaby
You probably meant "plain old JSP" there :)
BalusC
no just plain old JSF
vinod
+1  A: 

Here are several tutorials:

Take your pick. The first and the last ones seems very useful for your particular purpose. I however agree that a simple Validator is more than sufficient for this.

BalusC
@BalusC thanks for ur great support!!!! your all links are very useful
vinod