Question

I have got some interesting issue for you. I am creating a composite component. I know, that I can use ui:param for storing value and reuse it. But what if I store to this variable some relative value (#{component.namingContainer.clientId}) and want to reuse it as a constant? It is difficult to explain - here you have my code:

<ui:param name="rdfaComp" value="#{component.namingContainer.clientId}"/>

This is in the beginning of the page - I want to store exactly this ID and then use nothing else by this variable. But later if I reuse it inside elements with own IDs, it is bad. It is interesting, what happens - JSF doesn't take the same value, but a relative one. It reads once more #{component.namingContainer.clientId}, not the fixed value.

How to solve this, could you help me, please? THanks a lot.

UPDATED There is still one important condition: the variable rdfaComp have to be available immediately, because I reuse it in a Javascript function (on the same page). Like this:

<h:commandButton onclick="return selectText('#{rdfaComp}:editor', ...

I am afraid, it is necessarry to use relative ID chains like this: #{component.namingContainer.parent.namingContainer.parent.clientId} etd. But it is really awful. Is there another solution?

Was it helpful?

Solution

The <ui:param> indeed merely creates an alias and the EL expression is still deferred and evaluated on every access in the very same context as where it's been referenced (and thus not where it's been declared! that explains your concrete problem). Besides, the <ui:param> is designed to be used on <ui:include>, <ui:composition> and <ui:decorate> only.

Use <c:set> instead. It's capable of immediately evaluating an EL expression and storing its result in either request, view, session or application scope via the scope attribute.

<c:set var="rdfaComp" value="#{component.namingContainer.clientId}" scope="request" />

Update: you actually wanted to get the client ID of the composite component itself, here's how you can get it:

<c:set var="rdfaComp" value="#{cc.clientId}" scope="request" />

OTHER TIPS

It is solved - and I must apologise once more :-). I didn't describe correctly the issue - what I really wanted to do. I just wanted to work with the full client ID of the composite component. Finally I found a solution: #{cc.namingContainer.clientId}

Thanks anyway, your answers were very helpful!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top