How to extract first component ID from #{cc.clientId}?

962 views Asked by At

I neet to get a specific parent component ID in a composite component. I've only found out how to get the entire chain of IDs, namely as I wrote in the title: #{cc.clientId}. It delivers (I don't know how they're called) Id1:Id2:Id3, but I need only Id1, how can I get it?

1

There are 1 answers

0
BalusC On

You could use the fn:split() function for this:

xmlns:fn="http://java.sun.com/jsp/jstl/functions"
...

#{fn:split(cc.clientId, ':')[0]}

Another way is to use UIComponent#getNamingContainer() on the UIComponent#getParent():

#{cc.parent.namingContainer.parent.namingContainer.clientId}

There may be better ways depending on the concrete functional requirement and the code you have so far, both which are missing in your question. For example, if Id1 actually refers a <h:form>, then you could use render="@form" instead in the <f:ajax>.

The Id1:Id2:Id3 is by the way just called the client ID (as you see in generated HTML output). The Id1 part is actually the component ID (as you see in JSF source code). The prepending of NamingContainer IDs in client ID as in Id1:Id2:Id3 is also sometimes called woodstocking.