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
2010-09-28 14:29:14
@dannywartnaby but i need to create a custom component that's requirement
vinod
2010-09-28 14:31:44
Are you using Facelets? Or just plain ole JSF?
dannywartnaby
2010-09-28 14:53:29
You probably meant "plain old JSP" there :)
BalusC
2010-09-28 15:07:06
no just plain old JSF
vinod
2010-09-28 15:11:24
+1
A:
Here are several tutorials:
- Creating JSF Custom Components - Contains classic credit card example, JSF 1.0 targeted (old!)
- Building Custom JSF UI Components - Simple output component, JSF 1.1 targeted.
- Guidelines for designing JSF custom components - Sun/Oracle's guidelines. JSF 1.x targeted.
- JSF Component Development - Extended label component, JSF 1.1 targeted.
- Creating a custom JSF 1.2 component - Shuffler component, JSF 1.2 targeted.
- Creating JSF div component - Simple div component, JSF 1.1 targeted.
- Custom JSF component - Birthday - Displays today's date and birthdays, JSF 1.1 targeted.
- Component writing checklist - Overview of differences in JSF 1.0/1.1 and 1.2.
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
2010-09-28 15:06:37