1 Reply Latest reply on May 23, 2007 9:29 AM by michael kutsch

    Rerender not performed onselect

    michael kutsch Newbie

      I have a tree which I want to use for navigation. Unfortunately the wanted page is not rendered when I select a node. The rendering is done when I expand/collapse a node. I modified the jboss-richfaces-3.0.1rc2-samples/tree-demo a little bit. I think that the timestamp should also be rerendered when a node is selected but it is only rerendered when I expand/collapse a node.

      Thanks in advance.

      index.jsp:
      
       <body>
       <f:view>
       <h:form>
       <a4j:outputPanel id="treepanel" ajaxRendered="true">
       <rich:tree id="tree" switchType="server"
       value="#{bean.data}" var="data"
       changeExpandListener="#{bean.onExpand}"
       nodeSelectListener="#{bean.onSelect}"
       ajaxSubmitSelection="true" reRender="tree,treepanel,messagepanel"
       iconCollapsed="#{bean.iconCollapsed}"
       iconExpanded="#{bean.iconExpanded}"
       iconLeaf="#{bean.iconLeaf}"
       icon="#{bean.icon}">
      
       <rich:treeNode type="input" >
       <h:outputText value="#{data} : " />
       </rich:treeNode>
      
       </rich:tree>
       </a4j:outputPanel>
       </h:form>
       <br/>
       <a4j:status startText="...start..." />
      
       <a4j:log hotkey="O" />
       <br/>
       <a4j:outputPanel id="messagepanel" ajaxRendered="true">
       <a4j:include viewId="#{bean.messagePanel}"/>
       </a4j:outputPanel>
      
      
       </f:view>
       </body>
      
      



      messagepanel.jsp:
      <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j" %>
      <h:outputText value="#{bean.timestamp}" />
      
      


      Bean.java
      
      public class Bean {
       private TreeNode data;
      
       private TreeNode selectedNode = null;
      
       private Map selectedNodeChildren = new LinkedHashMap();
      
       private String iconCollapsed = null;
       private String iconExpanded = null;
       private String iconLeaf = null;
       private String icon = null;
      
       DateFormat fmt = DateFormat.getDateTimeInstance();
      
       String timestamp;
      
       public String getIcon() {
       return icon;
       }
      
       public void setIcon(String icon) {
       this.icon = icon;
       }
      
      
       public Bean() {
       try {
      
       data = XmlTreeDataBuilder.build(new InputSource(
       getClass().getResourceAsStream("test.xml")));
      
       } catch (SAXException e) {
       e.printStackTrace();
       } catch (IOException e) {
       e.printStackTrace();
       }
      
       initData();
       }
      
       public TreeNode getData() {
       return data;
       }
      
       private UITree getTree(FacesEvent event) {
       UIComponent component = event.getComponent();
       if (component instanceof UITree) {
       return ((UITree) component);
       }
      
       if (component instanceof UITreeNode) {
       return ((UITree) component.getParent());
       }
      
       return null;
       }
      
       public void onSelect(NodeSelectedEvent event) {
       System.out.println("Node selected: " + getTree(event).getRowKey());
       if (getTree(event).getTreeNode()!=null) {
       selectedNode = getTree(event).getTreeNode();
       initData();
       }
       }
      
      
       private void initData() {
       selectedNodeChildren.clear();
       if (selectedNode != null) {
       Iterator iter = selectedNode.getChildren();
       int i = 0;
       while (iter.hasNext()) {
       Map.Entry entry = (Map.Entry) iter.next();
       selectedNodeChildren.put(((TreeNode)entry.getValue()).getData(), Integer.toString(i++));
       }
       }
       }
      
       public void onExpand(NodeExpandedEvent event) {
       UITree tree = getTree(event);
       System.out.println("Node "
       + (tree.isExpanded() ? "expanded" : "collapsed") + " "
       + tree.getRowKey());
       }
      
       private UITree tree;
      
       public UIComponent getTree() {
       return tree;
       }
      
       public Map getSelectedNodeChildren() {
       return selectedNodeChildren;
       }
      
       public void setSelectedNodeChildren(Map selectedNodeChildren) {
       this.selectedNodeChildren = selectedNodeChildren;
       }
      
       public String getIconCollapsed() {
       return iconCollapsed;
       }
      
       public void setIconCollapsed(String iconCollapsed) {
       this.iconCollapsed = iconCollapsed;
       }
      
       public String getIconExpanded() {
       return iconExpanded;
       }
      
       public void setIconExpanded(String iconExpanded) {
       this.iconExpanded = iconExpanded;
       }
      
       public String getIconLeaf() {
       return iconLeaf;
       }
      
       public void setIconLeaf(String iconLeaf) {
       this.iconLeaf = iconLeaf;
       }
      
       public String getMessagePanel() {
       return "/pages/messagepanel.jsp";
       }
      
       public String getTimestamp() {
       timestamp = fmt.format( System.currentTimeMillis());
       return timestamp;
       }
      
      }
      




      faces-config.xml:
      
      <faces-config>
       <managed-bean>
       <managed-bean-name>bean</managed-bean-name>
       <managed-bean-class>org.richfaces.Bean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
      ...
      </faces-config>