Conditional Logic within dynamically generated datatable
taylorc Nov 8, 2010 10:25 AMGreetings,
In my app I am creating a page to manage user permissions. I am using an extendedDataTable where the rows represent Users and the columns represent different apps. Each cell has a toggle switch to enable or disable that app for that user.
I am using <a4j:support> to perform the permission toggle action when the toggle button image is clicked. I am able to do this because I can pass the user and app to the action using <f:param>.
However, I am unable to determine which image (toggle-on or toggle-off) should be displayed because I am unable to pass the app and user to a bean method in the rendered attribute on the image. Code Below:
<rich:columns value="#{permissionManagementBean.apps}" var="app" index="ind">
<f:facet name="header">
<h:outputText id="appHeader#{ind}" value="#{app.displayName}"/>
</f:facet>
<h:panelGroup id="permissionBox#{ind}">
<h:graphicImage id="onImage#{ind}" title="Click to disable" style="cursor:pointer;" url="/images/on.png" styleClass="cursorClass" rendered="#{permissionManagementBean.hasPermission">
<a4j:support id="onImageSupport#{ind}" event="onclick" action="#{permissionManagementBean.togglePermission}" reRender="permissionBox#{ind},allPermissionsBox" ajaxSingle="true">
<f:param id="onAppParam#{ind}" name="appId" value="#{app.appKey}"/>
<f:param id="onUserParam#{ind}" name="userId" value="#{user.unifiedAccountId}"/>
</a4j:support>
</h:graphicImage>
<h:graphicImage id="offImage#{ind}" title="Click to enable" style="cursor:pointer;" url="/images/off.png" styleClass="cursorClass" rendered="#{!permissionManagementBean.hasPermission}">
<f:param id="param1#{ind}" name="appId" value="#{app.appKey}"/>
<f:param id="param2#{ind}" name="userId" value="#{user.unifiedAccountId}"/>
<a4j:support id="offImageSupport#{ind}" event="onclick" action="#{permissionManagementBean.togglePermission}" reRender="permissionBox#{ind},allPermissionsBox" ajaxSingle="true">
<f:param id="offAppParam#{ind}" name="appId" value="#{app.appKey}"/>
<f:param id="offUserParam#{ind}" name="userId" value="#{user.unifiedAccountId}"/>
</a4j:support>
</h:graphicImage>
</h:panelGroup>
</rich:columns>
The issue is that permissionManagementBean.hasPermission (which is being called on the rendered attribute on the <h:graphicImage>s) has no idea which app or user it should be checking because I am unable to pass parameters to that call.
I could define the table columns statically and have app-specific permissions checks on the user objects, but I'd like for it to all be generated dynamically so that adding a new app won't require changing the code.
Anyone have an idea of a way to make this work dynamically?
Thanks