2 Replies Latest reply on Nov 30, 2010 6:36 AM by kandl

    tree selection ajax

    kandl

      Hi

       

      I have the following problem and I'm sure the solution isn't very complex for an programmer with more richfaces experience than me.

       

      I have a tree component on my site which represents a folder hirarchy from the computer. It's possible to create root and subfolders from the site. The rootfolder creation works fine, but to create a subfolder the user must select a node from the tree where the subfolder should be created. After a folder is created the tree is reloaded.

       

      The code for the tree looks like this:

           <rich:tree ajaxRendered=true ajaxSubmitSelection=true nodeSelectListener="#{myBean.processSelection}" switchType=ajax>

                <rich:recursiveTreeNodeAdopter......>

           <rich:tree>

       

      In the processSelection method I set the memberVariable selectedNode in myBean to the value of the selected node. The button should be enabled if a node from the tree is selected, otherwise not. And in the output text the user should see, where he creates a subfolder. I tried this with ajax like this:

       

      <a4j:outputPanel

           <h:panelGrid columns=3>

                <h:outputText value="Create subfolder in #{myBean.selectedNode}"

                <h:inputText value="#{myBean.subfolderName}

                <h:commandButton value="create"

                     disabled="#{myBean.selectedNode == null}"

                     action="#{myBean.createSubfolder}">

                          <f:param name="selectedVal" value="#{myBean.selectedNode}"/>

                </h:commandButton>

      .......

       

      The outputText works fine, if i select a node it's shown in the outputText field where the node should be created. The problem is, if I try this with ajax, the action method from the button is never called and so there is no subfolder created.

       

      I hope that someone can help me with this problem or can give me a hint how to solve this.

       

      Kind regards,

      candymen

        • 1. Re: tree selection ajax
          ilya_shaikovsky

          it seems that myBean is request scoped so on request from button -  #{myBean.selectedNode == null} condition are false again and actionEvent just not risen. make it session scoped or store with keep alive.

          • 2. Re: tree selection ajax
            kandl

            Thanks for reply,

             

            Yes the bean is request scoped. And I have modified the code a little bit to the following

             

            <a4j:outputPanel ajaxRendered="true">
                                    <h:panelGrid id="singleSubfolder" columns="3"
                                        rendered="#{recursiveTreeNodeAdopterBean.selectedNode != null}">

             

                                        <h:outputText id="subfolder1"
                                            value="Create Subfolder in #{recursiveTreeNodeAdopterBean.selectedNode}" />
                                        <h:inputText
                                            value="#{recursiveTreeNodeAdopterBean.singleSubFolderNameToCreate}" />
                                        <a4j:commandButton value="Create"
                                            action="#{recursiveTreeNodeAdopterBean.createSubfolder}">
                                            <f:param name="selectedVal"
                                                value="#{recursiveTreeNodeAdopterBean.selectedNode}" />
                                            <a4j:support event="oncomplete" reRender="treepanel" />
                                        </a4j:commandButton>
                                    </h:panelGrid>

             

                                </a4j:outputPanel>

             

            On the page I have a tree component which represents the file system. Then I have buttons for creating a root folder and a button for creating a subfolder in each root folder. After creating them I reRender the tree.

            The problem now is with the create a Single subfolder in the selected folder. As mentioned before with request scope the action method isn't called. But the problem is, that with a4j:keepAlive or with session scope the tree doesn't reRender. Alternatively I have to do a full page reload, but that's not acceptable, because of performance issues.

             

            Is there a possibility that both issues(the reRender from the tree after creating any folder) and to show the panel from the code only if a node is selected and the action is also called.

             

            I'm getting very frustrated about that problem.

             

            Hope that someone can help me.

             

            Kind regards