2

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"
    sortFunction="#{dataTableUtil.sort}">  

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

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.

Thanks!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
pmilkman
  • 101
  • 9

2 Answers2

2

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

<p:ajax event="rowSelect" 
        listener="#{fileCabinet.onRowSelect}"   
        update=":form:directoryTable :menu" 
        disabled="#{directoryObject.objectType ne 'DIRECTORY'}" />                              
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
pmilkman
  • 101
  • 9
0

Since 4.0 version, Primefaces datatable comes with a disabledSelection property.

<p:dataTable var="foo" value="#{bean.foos}" selection="#{bean.selectedFoo}" disabledSelection="#{foo.bar == 1}">
    <p:column selectionMode="single" />
    <p:column>
        <h:outputText value="#{foo.bar}" />
    </p:column>
<p:dataTable>
Joe
  • 4,460
  • 19
  • 60
  • 106