7 Replies Latest reply on Nov 5, 2008 11:35 AM by Ilya Shaikovsky

    Weird tree node behavior (RichFaces + Seam)

    Andrew Fuqua Newbie

      Background: a dynamic 2-level tree, both levels comprised of data from a Seam session bean. I just want to know which node is selected when a user clicks on it, and then refresh an outputText element with the new selected node. Upon clicking the 2nd-level node the node text changes. See the following video: http://vimeo.com/2147584 Notice how the 2nd tier node content changes every time I select that node. The node listener code in the bean runs, but it does nothing to change the node text as far as I can see. Relevant snippets of code follow below.

      Any idea what the problem could be? Remember to watch the video in the link above. Thanks for your insight!

      Andrew

      p.s. Please don't dismiss this as a Seam problem and tell me to post in another forum. RichFaces is supposed to work with Seam. If you can tell me how to configure Seam differently to work with RichFaces, that would be nice. Or tell me how to configure RichFaces to work with Seam. The point is they aren't working together on this simple task and they need to do so.


      Here are the relevant snippets of code:


      Facelets:
       <a:form ajaxSingle="true" ajaxSubmit="true">
       <h:outputText value="Selected Auction #{uifront.curAuctionValue.toString()}" id="selected" />
       <rich:tree id="AuctionSelect" switchType="ajax"
       nodeSelectListener="#{uifront.selectionListener}"
       ajaxSubmitSelection="true" >
      
       <rich:treeNodesAdaptor id="AUCTION" nodes="#{auctionList.resultList}" var="auct">
       <rich:treeNode data="#{auct.id}" >
       <h:outputText value="Auction: #{auct.auctDesc} #{auct.id}" />
       </rich:treeNode>
      
       <rich:treeNodesAdaptor id="AUCTIONVALUE" nodes="#{auct.auctionValues}" var="avs">
       <rich:treeNode data="#{avs.id}">
       <h:outputText value="Value: #{avs.value}" />
       <a:support event="onclick" reRender="selected"/>
       </rich:treeNode>
       </rich:treeNodesAdaptor>
       </rich:treeNodesAdaptor>
       </rich:tree>
       </a:form>
      


      Listener:
      @Name("uifront")
      @Scope(ScopeType.SESSION)
      public class UiFront {
      
       @In
       protected EntityManager entityManager;
      
      ...
       private AuctionValue curAuctionValue;
      
       public void selectionListener(NodeSelectedEvent event) {
       UITree tree = (UITree) event.getComponent();
       AuctionValue av = (AuctionValue) tree.getRowData();
       this.curAuctionValue = av;
       System.out.println ("rowdata: " + tree.getRowData() + " Tree rowdata: " + av.toString());
       }
      ...
      }
      







        • 1. Re: Weird tree node behavior (RichFaces + Seam)
          Nick Belaevski Master

          Andrew,

          Looks like the problem is caused by the fact that data items contained in #{auct.auctionValues} does not have constant indexes. Tree re-renders selected node and does that basing on its index inside collection - but there's another data on that place for the next time. It is easy to check if that is the real reason of the problem: switch tree to client mode and compare its behavior with

          ajaxKeys="#{null}"
          - that should disable all ajax updates for tree and without.

          P.S. What RF and Seam versions are used?

          • 2. Re: Weird tree node behavior (RichFaces + Seam)
            Andrew Fuqua Newbie

            I am using Seam 2.0.3.CR1 and RichFaces 3.2.2.CR3.

            I added switchType="client" ajaxKeys="#{null}" and the tree of course did not re-draw after selecting a node. However, in the output textbox that is updated after the selection, text from unselected nodes still appeared. This indicates to me that even though the tree was not re-drawn, the model beneath the visible tree pointed to another node besides the one that was visible. I guess I can fix that by finding a way to keep the underlying collection data structure in a well-defined order.

            According to RichFaces documentation, the ajaxKeys property is not on treenode tree or the tree adapter. But it works anyway, so I guess it is an undocumented feature?

            Where is the documentation for what is sent in the selection event? The event component is a UITree if a parent is selected, and it's a HTMLTreeNode if the child is selected? I have no idea how to get to the useful data given an HTMLTreeNode. Specifically, what's the HTMLTreeNode analog to getRowData() on the UITree?


            • 3. Re: Weird tree node behavior (RichFaces + Seam)
              Nick Belaevski Master

               

              "elenctic87" wrote:
              I am using Seam 2.0.3.CR1 and RichFaces 3.2.2.CR3.

              Can I ask why not 3.2.2.GA?

              "elenctic87" wrote:
              According to RichFaces documentation, the ajaxKeys property is not on treenode tree or the tree adapter. But it works anyway, so I guess it is an undocumented feature?

              Yes, that's a standard feature that somehow got hidden in attributes table: https://jira.jboss.org/jira/browse/RF-4541 and thus left undocumented in the section of documentation about tree component.

              "elenctic87" wrote:
              Where is the documentation for what is sent in the selection event? The event component is a UITree if a parent is selected, and it's a HTMLTreeNode if the child is selected? I have no idea how to get to the useful data given an HTMLTreeNode. Specifically, what's the HTMLTreeNode analog to getRowData() on the UITree?


              For selection event: the only case when HtmlTree itself is the source of the event is when you do not use rich:treeNode at all so rich:tree creates one implicitly. For the other cases corresponding HtmlTreeNode (matching is done by value of "nodeFace" tree attribute expression and node "type" attribute value) is the source of the event. That is so because rich:treeNode can have its own set of listeners, attributes, etc.. You can do this:
              public void onNodeSelection(NodeSelectedEvent event) {
               UITreeNode treeNode = (UITreeNode) event.getComponent();
               Object rowData = treeNode.getUITree().getRowData();
               }
              


              • 4. Re: Weird tree node behavior (RichFaces + Seam)
                Andrew Fuqua Newbie

                I'm using RichFaces 3.2.2 CR3 because that's what came with Fiji, which is another component of my app. As I was having some difficulty with Fiji, I didn't want to try a version different than the supplied version (to eliminate versions as a source of the problem). Now that Fiji is working for me, I will upgrade to RF 3.2.2 GA. I will also upgrade Seam to 2.1.0 GA.

                The onNodeSelection code works great. Where can that information be found in the documentation? Basically, if you weren't here to answer that question for me, where could I have found out how to do that? I'm looking for a good source so I can learn myself without having to come to the forums for every little question. I do appreciate your help on this issue!

                • 5. Re: Weird tree node behavior (RichFaces + Seam)
                  Nick Belaevski Master

                  Andrew,

                  I'm sorry, but after code exploration I need to make a correction: source of the event is the component the listener is defined at. If listener is defined on rich:tree then HtmlTree is the source and if it is defined on rich:treeNode then HtmlTreeNode is the source.

                  • 6. Re: Weird tree node behavior (RichFaces + Seam)
                    Andrew Fuqua Newbie

                    Ok, I attached the listener to the second-level rich:treeNode. An HtmlTreeNode came through in the event handler. Casting it to a UITreeNode still works. Is that inadvisable (casting to UITreeNode)?

                    I'm still wondering where this type of thing is documented. You mentioned you looked at the source code. Is that the main source of information about this type of thing? That's daunting to think I need to understand RichFaces source in order to use it. It's hard to develop RichFaces backing bean code when I really don't know what type of objects to expect in methods nor how to get the relevant information from them. I could engage in guess-and-check (i.e. let's use a debugger or println stmt to find out what kind of object I'm dealing with), but that is extraordinarily unproductive for the developer. Any pointers to better sources?


                    • 7. Re: Weird tree node behavior (RichFaces + Seam)
                      Ilya Shaikovsky Master

                      Currently there are next informational sources

                      Our wiki page There are some articles and cookbook notes.

                      Our official documentation

                      Live demo It contains not only from our standard simple howtos, but additionally filled with most popular forum cases.

                      And for sure you could freelly use this forum and it will help us to reduce the gaps in current documentation.