views:

343

answers:

3

I have JSF code like:

<h:inputText id="from" value="#{fromToMBean.fromName}"/>

I would like to get this element from JavaScript by ID (from), but I can't, because in generated HTML it is j_idt8:from

How can I get this element in e.g. jQuery? Is there any way to force JSF2 not to change ids?

+1  A: 

You can either use a custom class which you only assign to this element and use css selectors or assign an id to the form and get the element with the id formid:from.

FRotthowe
A: 

In JSF 1.2 you can use forceId="true". I'm not sure if you can use t:input in JSF 2, but you should be able to. Then it's ID in HTML will be what you expect.

Jon
A: 

In order to achieve full ID for a component, use EL implicit objects and their properties such as #{cc.clientId} and #{component.clientId}. Source: Acquire full prefix for a component clientId inside naming containers with JSF 2.0.

Tuukka Mustonen