user566702
user566702

Reputation: 81

Java Server Faces JSF - who is responsible for auto generated id's?

when the Faces Servlet compiles a jsp to the servlet in the work directory, it generates id's, like j_id_jsp_1024919151_1...

When is the id changing? I tried it on the same machine, cleaning work directory, still the same. I started another Apache Tomcat on the same machine and I got new id's...

Thanx Stefan

Upvotes: 8

Views: 3099

Answers (3)

McDowell
McDowell

Reputation: 108909

The id of a component is generated by the implementation if it is not set.

The id attribute value emitted to the page is the client identifier. This is constructed using the rules defined in the link and will include parent NamingContainer ids and possibly the view namespace.

You can read more about working with JSF client identifiers here.

Upvotes: 10

darioo
darioo

Reputation: 47183

ID generation would be implementation dependent. By this, I mean any JSF implementation you use will have a mechanism for generating IDs based on variables that are "good enough" for unique identification. Possibly: class name, html element name, etc....

You might want to check reference implementation's source code.

Upvotes: 0

mvg
mvg

Reputation: 1584

JSF automatically generate ids for the component during the lifecycle when you don't specify any. If you don't want this feature then set the id for all the components individually and set the id for <h:form> also to avoid this.

Also setting the id by yourself will help you more in Javascript based validation where the values of the fields are derived using ids

Upvotes: 3

Related Questions