My scenario is the following: I have a primefaces p:treeTable
which contains log files to download. If my selected node is not null there is no problem, the file will be downloaded and the tree will stay expanded so I can download other files from the same node, but if the selected node is null or there is some Exception
, I will like to display a message without collapse all nodes the user has already expanded. Thats the behaviour I want to avoid as all tree gets collapsed.
I lookout for a solution and I try to implements some of those exposed in this link but no one works for me.
Here is my xhtml
:
<p:outputPanel id="log">
<div style="height:35px;">
<p:commandButton id="btnDownload" value="Download"
actionListener="#{loggerView.download}" ajax="false" icon="ui-icon-arrowthick-1-s"
styleClass="ui-priority-primary">
<p:fileDownload value="#{loggerView.file}" />
</p:commandButton>
</div>
<p:treeTable id="tableLogs"
value="#{loggerView.tree}"
var="log"
style="width:100%;"
selectionMode="single"
selection="#{loggerView.selectedLog}" >
<f:facet name="header">
Logs
</f:facet>
<p:column headerText="Log name" style="width:40%">
<h:outputText value="#{log.nombre}" />
</p:column>
<p:column headerText="Last modification date" style="width:30%">
<h:outputText value="#{log.date}" />
</p:column>
<p:column headerText="Log size" style="width:27%">
<h:outputText value="#{log.kilobytes}" />
</p:column>
</p:treeTable>
</p:outputPanel>
And my View
:
@ManagedBean(name = "loggerView")
@ViewScoped
public class LoggerView implements Serializable {
private DefaultTreeNode selectedLog;
// OTHER VARIABLES, METHODS, GETTERS AND SETTERS...
public void download() {
if (selectedLog != null) {
try {
// HERE I GET MY LOG TO DOWNLOAD AND IT'S WORKING JUST FINE
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR", "Getting the file!"));
}
} else {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "WARNING", "The log is null!"));
}
}
}
As you can see, if my selectedLog
is null or if I catch
an Exception
getting the file I display a message and then is when the tree is collapsed.
Can anyone tell me how can I avoid this behaviour?
Thanks in advance!!