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();

}

[3468 byte] By [fikria] at [2007-10-2 18:42:08]
# 1
Any help? please?
fikria at 2007-7-13 20:04:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Try removing the transient property.

To avoid the duplicate problem, verify, before creating the component if the component is already on the tree.

transient - A flag indicating whether this instance has

decided to opt out of having its state

information saved and restored. The

default value for all standard component,

converter, and validator classes that

implement StateHolder must be false.

By other words -

?void setTransient(boolean newValue)

?boolean isTransient()

Set and get the transient property. When this property is set, the state is not

saved.

pringia at 2007-7-13 20:04:22 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...