5 Replies Latest reply on Jan 30, 2010 3:55 PM by bikramjit saha

    link in richfaces tree menu

    safa said Newbie

      Hi,
      I work with jboss seam2.0.3 and richfaces;
      I have a treemenu:


      <rich:tree 
                                      style="width:300px" 
                                      rendred="true"
                                      nodeSelectListener="#{menu1.processSelection}" 
                                      reRender="selectedNode" 
                                      switchType="client" 
                                      value="#{menu1.treeNode}" 
                                      ajaxKeys="#{null}"
                                      ajaxSubmitSelection="true"
                                      var="item">
                              </rich:tree>
              
      




      it work very well, but I would like to be redirected to an other page when I click on a tree node,
      Have any body any idea??


      thx


        • 1. Re: link in richfaces tree menu
          wen ma Newbie

          I have the same question. Does anyone have a solution?


          thanks,

          • 2. Re: link in richfaces tree menu
            Jakub Janczak Newbie
            <rich:tree ... var="item">
              <rich:treeNode>
                 <h:outputLink value="#{item.text}" action="#{item.action}" />
              </rich:treeNode>  
            </rich:tree>
            



            and action is a normal jsf action with string outcome


            class Item {
              public String action() {
                 return "massive shouts"
              }
            }
            



            i think it should work,


            PS: massive shouts is from www.bassdrive.com :)

            • 3. Re: link in richfaces tree menu
              praveenkumar kalamani Newbie

              I have the same problem... can have full code for it.
              With bean and as well as link forming in the tree.


              thanks in advance.

              • 4. Re: link in richfaces tree menu
                praveenkumar kalamani Newbie
                Hi,

                After adding the following call with URL link



                public class NodeData {
                   
                        private String nodeText;

                    private Boolean selected = Boolean.FALSE;
                   
                     
                    private String url;
                   
                   
                        public NodeData(String nodeText,String url) {
                        this.nodeText = nodeText;
                        this.url= url;
                    }


                         public String getUrl() {
                                return url;
                        }

                        public void setUrl(String url) {
                                this.url = url;
                        }

                        public String getAction(){
                                        System.out.println(" This is called at least  "+this.url);
                                return this.url;
                        }

                        public String getNodeText() {
                                return nodeText;
                        }

                        public void setNodeText(String nodeText) {
                                this.nodeText = nodeText;
                        }

                        public Boolean getSelected() {
                                return selected;
                        }
                        public void setSelected(Boolean selected) {
                                this.selected = selected;
                        }

                   
                }

                it throws following exception :

                javax.servlet.ServletException: #{node.url}: javax.el.MethodNotFoundException: /provisioningTreeNew.jsp @37,90 action="#{node.url}": Method not found: com.techm.cisco.jbpm.component.tree.NodeData@36acab.url()


                Please let if implemented such example.

                Thanks in advance
                • 5. Re: link in richfaces tree menu
                  bikramjit saha Newbie
                  XHTML :

                  Add the below tag in your XHTML page

                  <rich:tree value="#{TreeBean.tree()}" var="node" switchType="client" rowKeyConverter="org.richfaces.TreeRowKeyConverter" nodeSelectListener="#{TreeBean.processNodeSelection}" ajaxSubmitSelection="true"  iconExpanded="true">
                  </rich:tree>


                  Backing Bean :
                  public TreeNodeImpl tree(){
                          TreeNodeImpl<String> data = new TreeNodeImpl<String>();
                            
                          for (int i = 0; i < components.length; i++) {
                               TreeNode<String> child = new TreeNodeImpl<String>();
                               child.setData(components[i]);
                               data.addChild(components[i], child);
                              
                               for (int j = 0; j < attributes[i].length; j++) {
                                    TreeNode<String> grandChild = new TreeNodeImpl<String>();
                                    grandChild.setData(attributes[i][j]);
                                   
                                    child.addChild(attributes[i][j], grandChild);
                         
                                    
                               }
                          }
                          return data;


                  Add a Listener code in your backing bean which will redirect the page to the desired url:



                  private Object selectedNodeData;

                            public String processNodeSelection(NodeSelectedEvent event) {
                              HtmlTree tree = ((HtmlTree) event.getComponent());
                             
                              selectedNodeData = tree.getRowData();
                             
                              if(selectedNodeData.equals("Periods")){
                                  FacesContext context = FacesContext.getCurrentInstance();
                                  HttpServletResponse response = (HttpServletResponse)context.getExternalContext().getResponse();
                                  try {
                                                  response.sendRedirect("/login.seam");
                                          } catch (IOException e) {
                                                  // TODO Auto-generated catch block
                                                  e.printStackTrace();
                                          }

                                  return "/login.seam";
                              }
                                  return null;
                            }

                            public Object getSelectedNodeData() {
                              return selectedNodeData;
                            }