user679526
user679526

Reputation: 845

JSF 2.0 cannot find component id in view

I have given the id of the input text with date_m. When I try to access the page it gives an error saying component id date_m not found in view. But I do not get this error when the id is changed to date-m. Does JSF not allow underscore for id's? IN our project the javax.faces.SEPARATOR_CHAR is underscore.

<h:inputText id="date_m" value="{bean.month}"/>
<h:message id="error" for="date_m"/>

Upvotes: 1

Views: 2067

Answers (2)

BalusC
BalusC

Reputation: 1108722

The component ID should not contain the same character as the separator character. That's among others why the default separator character is :. You cannot use it in the component ID, it would be invalidated according the rules of UIComponent#setId(), but it is allowed in HTML element IDs.

However, if you change the default separator character by a javax.faces.SEPARATOR_CHAR context parameter to a character which is allowed in component IDs, then you should be double as careful when specifying component IDs. You should namely make sure that you don't use exactly the separator character in the component ID, otherwise the UIViewRoot#findComponent() method may break. This method is internally used by JSF to find components by client ID.

So, if your separator character is _, then you should use it nowhere in your component IDs. The logical consequence is to consequently use - instead.

See also:

Upvotes: 2

AlanObject
AlanObject

Reputation: 9943

If your separator character is "_" then I think you have confused the lookup algorithm by using an underscore in your id field.

Try removing the underscore (from "date_m" to "datem") and see what happens then.

Upvotes: 1

Related Questions