0

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!!

Community
  • 1
  • 1
CarlosLeo
  • 123
  • 2
  • 10
  • You can make an expand ajax look's like this `` – Yagami Light Jul 27 '16 at 10:32
  • @YagamiLight you mean the solved solution exposed on the [link](http://stackoverflow.com/questions/25358328/avoid-nodes-of-ptreetable-to-collapse-after-update) I mention in the post? I don't know why but this is not working for me :-( – CarlosLeo Jul 27 '16 at 10:41
  • mmm... maybe I need to add `update=":tree"` to the ajax event? Will try it – CarlosLeo Jul 27 '16 at 10:44
  • Hi i am sorry i missed up the link, if you can't use expand use rendered with null condition – Yagami Light Jul 27 '16 at 10:45

0 Answers0