How to get jsf clientid component in datatable?

I am trying to get the component client id in datatable. the problem is that jsf puts the row index before the component id automatically, i.e.

<a id="mappedidentifier_table:1:mappedidentifier_Update" href="#">Update</a> 

for the link in the second line (index = 1).

I use the following methods to get clientId

  public static String findClientId(String id) { FacesContext context = FacesContext.getCurrentInstance(); UIViewRoot view = context.getViewRoot(); if (view == null) { throw new IllegalStateException("view == null"); } UIComponent component = findComponent(view, id); if (component == null) { throw new IllegalStateException("no component has id='" + id + "'"); } return component.getClientId(context); } private static UIComponent findComponent(UIComponent component, String id) { if (id.equals(component.getId())) { return component; } Iterator<UIComponent> kids = component.getFacetsAndChildren(); while (kids.hasNext()) { UIComponent kid = kids.next(); UIComponent found = findComponent(kid, id); if (found != null) { return found; } } return null; } 

however this returns

mappedidentifier_table:mappedidentifier_Update ,

instead

mappedidentifier_table:1:mappedidentifier_Update ,

therefore, it does not match any element because there is no row index in id.

I read http://illegalargumentexception.blogspot.com/2009/05/jsf-using-component-ids-in-data-table.html

however, I intend to have a simpler implementation, rather than a TLD function or chips like the author.

Anyone have any thoughts?

thanks,

J

+4
source share
1 answer

however this returns mappedidentifier_table:mappedidentifier_Update instead of mappedidentifier_table:1:mappedidentifier_Update

This will happen if you allow clientId out of line context. String context is configured at each stage of the life cycle using the UIData control.

This can happen if you use immediate evaluation instead of deferred evaluation in your EL expressions - ${} instead of #{} .

As an aside, and, as noted in the article, this search algorithm will work only if the identifier of the component is unique to the presentation; spec says it should be unique to NamingContainer only; this should not be a problem if you are careful with the unique identifiers of the components on your page.

+3
source

All Articles