1

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"/>
user679526
  • 845
  • 4
  • 16
  • 39

2 Answers2

2

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I've been experiencing this problem and didn't know why or how to solve it. Thanks for the explantaion, I didn't know about that. – jmrodrigg Nov 09 '12 at 13:56
1

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.

AlanObject
  • 9,613
  • 19
  • 86
  • 142