Conditionally apply AJAX events to datatable rows

I'm relatively new to JSF and Primefaces, but I've been tasked to try and reduce the amount of AJAX requests made in a legacy codebase. This question is from a particular example where we have a directory listing UI of files and folders.

<p:dataTable id="directoryTable" var="directoryObject" value="#{fileCabinet.folderContents}" 
    resizableColumns="true" scrollable="true"
    rowKey="#{directoryObject}" selectionMode="single"
    selection="#{fileCabinet.currentObject}" dblClickSelect="true"
    sortMode="multiple" emptyMessage="This folder is empty"

    <c:if test="#{directoryObject.objectType eq 'DIRECTORY'}">
        <p:ajax event="rowSelect" listener="#{fileCabinet.onRowSelect}"   
                            update=":form:directoryTable :menu" />                              

I've excluded the rest of the datatable for brevity. With this code, the ajax event is never attached even though the 'test' expression evaluates perfectly fine in subsequent 'rendered' attributes of html elements later on. Unfortunately, p:ajax doesn't support 'rendered' conditionals.

I've also tried c:choose / c:when, to the same results.

This feels like something that should be really easy to do! I'm probably missing some simple syntax to make this work.



I fixed this by using the disabled attribute for <p:ajax> with my conditional as the value (negated of course).

<p:ajax event="rowSelect" 
        update=":form:directoryTable :menu" 
        disabled="#{directoryObject.objectType ne 'DIRECTORY'}" />                              

Need Your Help

Updatable composite component?

jsf primefaces components composite

I have a problem with a composite component.

Can we have content text directly in <div>?


can we have content text directly in &lt;div&gt;text content&lt;/div&gt; or it should be like &lt;div&gt;&lt;p&gt;text content&lt;/p&gt;&lt;/div&gt;? according to web standards.