Conversion and Validation not working on custom component ?
Hi all,
I'm having a problem with the creation of a JSF custom component. My custom component renders itself as a standard InputText or as a myFaces Calendar ( depending on an attribute of the object it is bound to). In the EncodeBegin() method of my custom component, I dynamically add the InputText or the Calendar component to the components tree.
It works fine so far: The component is rendered correctly in a form. But the problem is that the validation and conversion are not triggered when the form is submitted. Looks like the there is no validation even though the setRequired(true) is called upon creation of my component? There is no validation or conversion wether it is rendered as an inputText or as a Calendar.
Can anybody help on this?
Thanks.
Fikri.
Here is some sample code to give a better idea:
Custom Tag in a jsp page:-
...
<my:field value="#{parameter}" />
...
Field component:--
...
publicclass FieldComponentextends UIInput{
...
publicvoid encodeBegin(FacesContext context)throws IOException{
if (!fieldType.equalsIgnoreCase("date")){// render as inputText
UIInput inputText = (UIInput) context.getApplication().createComponent(UIInput.COMPONENT_TYPE);
inputText.setId("paramValue");
inputText.setRequired(true);// Doesn't work ?!
inputText.setConverter(new IntegerConverter());
inputText.setTransient(true);// avoid "duplicate component" error
this.getForm().getChildren().add(inputText);
inputText.encodeBegin(context);
inputText.encodeEnd(context);
}else{//render as Calendar
HtmlInputCalendar calendar = (HtmlInputCalendar)context.getApplication().createComponent(HtmlInputCalendar.COMPONENT_TYPE);
calendar.setId("paramDate");
calendar.setPopupDateFormat("dd/MM/yyyy");
calendar.setRenderAsPopup(true);
// Add a converter to the calendar
DateTimeConverter dateConverter =new DateTimeConverter();
dateConverter.setPattern("dd/MM/yyyy");
calendar.setConverter(dateConverter);
calendar.setRequired(true);// Doesn't work ?!
calendar.setTransient(true);// avoid "duplicate component" error
this.getForm().getChildren().add(calendar);
calendar.encodeBegin(context);
calendar.encodeEnd(context);
}
writer.flush();
}

