Reputation: 3257
I am fixing a PrimeFaces panel with a file downloader where you select a file from a list and download it.
Right now first you have to select the file with a left click and then right click and select "download file".
Most people however are used to right click on a file and select "download it".
As you can see from the code below when you select a file the actionlistener actionListener="#{downloadsController.selectFile}" is called which correctly sets the file name to be downloaded and then the right click calls actionListener="#{downloadsController.downloadFile}".
How can I make selectFile be called when right click is called? or let right click access the file.name ?
<p:panel id="propPanel">
<h:form>
<p:contextMenu for="fileExplorer">
<p:menuitem value="Download" actionListener="#{downloadsController.downloadFile}"
icon="ui-icon-arrowthickstop-1-s" ajax="false" >
<p:fileDownload value="#{downloadsController.fileToDownload}" />
</p:menuitem>
</p:contextMenu>
<p:scrollPanel style="height:300px">
<p:dataTable id="fileExplorer" var="file" value="#{downloadsController.files}"
emptyMessage="This folder is empty"
rowKey="#{file.name}" selectionMode="single" >
<p:column style="width:308px" sortBy="#{file.name}">
<f:facet name="header">
Name
</f:facet>
<p:commandLink style=" text-decoration: none;"
actionListener="#{downloadsController.selectFile}" update=":treePanel">
<f:param name="fileName" value="#{file.name}"/>
<p:spacer width="5" height="10" />
<h:outputText value="#{file.name}" escape="false"/>
</p:commandLink>
</p:column>
<p:column style="width:55px" sortBy="#{file.size}">
<f:facet name="header">
Size
</f:facet>
<h:outputText value="#{file.size}" escape="false">
</h:outputText>
</p:column>
</p:dataTable>
</p:scrollPanel>
</h:form>
</p:panel>
Upvotes: 1
Views: 1119
Reputation: 4423
If you are using Primefaces 4 you could simply use row selection as demonstrated here.
<p:contextMenu for="cars">
...
</p:contextMenu>
<p:dataTable id="cars" var="car" value="#{tableBean.carsSmall}" rowKey="#{car.model}"
selection="#{tableBean.selectedCar}" selectionMode="single">
...
</p:dataTable>
Upvotes: 2