Is the identifier generated by JSF the same for different versions and implementations?

We are going to write a complete test suite for one of our JSF applications using Selenium.

It still seems that there are two preferred approaches to uniquely identifying each element: by identifier or by using a unique class name. Later it is really a hack and does not make sense semantically. The first approach is correct, but element identifiers are generated by JSF.

All of the various JSF implementations I've seen seem to use the same approach: use the parent element as a namespace and then concatenate the element identifier with a colon. Fair enough.

Question: did you know that this is guaranteed in some part of the JSF specification? It would be a real problem to find out later that we need to rewrite all component selectors in the tests just because JSF xy has changed the way the identifier names are generated.

Thanks!

+4
source share
3 answers

JSF typically generates a component identifier if the identifier attribute is not explicitly specified. It will be generated in j_idXXX (XXX will be number incremented) format j_idXXX (XXX will be number incremented)

 <h:form id="LoginForm"> <h:inputText id="userName" .../> </h:form> 

for this, an inputText identifier will be generated as LoginForm:userName , and if id is not explicitly specified, then it will be generated somehow like LoginForm:j_id15

This is mentioned in the JSF specification in section 3.1.6, but the exact format is not specified. ClientId is created using this method UIComponent.getClientId(); Follow this link UIComponent

+4
source

Is the identifier generated by JSF the same for different versions and implementations?

No. You must explicitly specify the component identifier in the UIInput component of UIInput and all its parent UINamingContainer components, such as <h:form> , <ui:repeat> , <h:dataTable> , etc. Independently. These identifiers will be destroyed by default using the delimiter character :

However, the delimiter character, in turn, is configured with JSF 2.0. So, if you change the separator character for your webapp from : to - or something else, then you will have to rewrite selenium tests that rely on the identifiers of the HTML elements.

+2
source

From JSF Specification (2.1) :

The client identifier is derived from the component identifier (or the result of calling UIViewRoot.createUniqueId() , if there is more than one), and the client identifier of the nearest parent component is NamingContainer according to the specified algorithm in javadoc for UIComponent.getClientId() . The rendering associated with this component, if any, will then be asked to convert this client identifier into a form suitable for sending to the client. The value returned by this method must be the same throughout the life cycle of the component instance, if setId() not, in which case it will be recalculated by the next call to getClientId() .

In addition to the specification, third-party plugins can affect the client identifier (for example, protlet bridge APIs).

+1
source

All Articles