Say I have a list of objects over which is iterated with an <ui:repeat> tag and the user has a list of actions for every object, but - depending on his permissions - some of those actions are disabled, because the user lacks the permission.
<ui:repeat var="item" value="#{myBean.selectedItems}">
<h1>#{item.name}</h1>
<h:commandButton value="Edit" disabled="#{myBean.getPermissions(item, user).has('EDIT') .../>
<h:commandButton value="Move" disabled="#{myBean.getPermissions(item, user).has('MOVE') .../>
<h:commandButton value="Copy" disabled="#{myBean.getPermissions(item, user).has('COPY') .../>
<h:commandButton value="Delete" disabled="#{myBean.getPermissions(item, user).has('DELETE') .../>
<h:commandButton value="Rotate" disabled="#{myBean.getPermissions(item, user).has('ROTATE') .../>
</ui:repeat>
So lets say, the operation to retrieve the permissions [myBean.getPermissions()] is quite expensive and I don't want it to be executed multiple times for one item.
So what can I do in JSF/EL to achive this?
Lets say I use a <ui:param> like this:
<ui:repeat var="item" value="#{myBean.selectedItems}">
<h1>#{item.name}</h1>
<ui:param name="itemPermissions" value="#{myBean.getPermissions(item, user)"/>
<h:commandButton value="Edit" disabled="#{itemPermissions.has('EDIT') .../>
<h:commandButton value="Move" disabled="#{itemPermissions.has('MOVE') .../>
<h:commandButton value="Copy" disabled="#{itemPermissions.has('COPY') .../>
<h:commandButton value="Delete" disabled="#{itemPermissions.has('DELETE') .../>
<h:commandButton value="Rotate" disabled="#{itemPermissions.has('ROTATE') .../>
</ui:repeat>
But as far as I understand, the <ui-param> is just a shortcut, it does not cache the actual value associated with it, but the value-expression is re-evaluated every time it is used? Is this correct?
So what can I do else? <c:set> is not an option, because it is only set during view-build-time afaik.
Is the only option, to cache the permissions manually in a bean variable and then use the bean to access them again? Is there no mechanism in JSF/EL that allows to define a variable (like in a normal Java method) that I can set a value to and read the value later?
And I noticed, that the rendered=".." or disabled=".." gets called sometimes even multiple times, so the expressions are not only evaluated once per tag, but in some case 2-3 times. Is this a correct observation and what's the reason for this?
Thanks in advance for your answers.
Edit: BalusC marked it as duplicate of a question, but I didn't find their an answer, as <c:set> that is recommended there does not work in my case. Or do you want to say, that it is not possible and if I want to cache it e.g. in an ui-repeat I have to do that with a bean for myself?