hi there,
i am trying to get the client id of a component in a datatable. the problem is that jsf puts row index before the component id automatically, i.e.
<a id="mappedidentifier_table:1:mappedidentifier_Update" href="#">Update</a>
for a link in the second row (index=1).
i am using the following methods to get the 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 of
mappedidentifier_table:1:mappedidentifier_Update
,
therefore it does not match any element cause the row index in id is missing.
i've 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 TLD function or facelets like the author did.
does anyone have any thoughts ?
thanks,
dzh