You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Silverman, Glenn" <GS...@dylt.com> on 2008/09/08 23:43:13 UTC

How can I preventTrinidad navigationPane from going back to the first groupNode in the menu model

Can anyone tell me now to prevent the NavigationPane in Trinidad from going back to the first groupNode in the menu model. Normal expected useage would suggest that the groupNode remain the same unless
another node is specifically clicked on by the user. But that is not what happens in the NavigationPane.  

Here is all the code I use to create the problem. The test is simple. Go to the "All Codes" menu tab (It's the second one) and click on the Enter button once. Then click on the tabs and everything
seems to work as expected. Ahhh...but click on the Enter button not once, but twice and then click on any of the tabs. The page goes back to the first groupNode, in this case, Error Messages, when
it should stay on All Codes. 

Can anyone tell me if there's a flaw in my code, below, that is causing this and if so, what is the solution?

I have a web page, index.jspx,  that includes a navigation tree that uses an XMLMenuModel, and a navigationPane using the same menu model, and a switcher to toggle
the content, as follows: 

			<tr:panelHorizontalLayout valign="top">						
						<tr:navigationTree value="#{root_menu}" var="foo">
							<f:facet name="nodeStamp">
								<tr:commandNavigationItem text="#{foo.label}" action="#{foo.doAction}"/>
							</f:facet>
						</tr:navigationTree>
                                    <tr:panelGroupLayout layout="vertical">                          
							<tr:navigationPane var="foo" value="#{root_menu}" level="1" >
							  <f:facet name="nodeStamp">
							    <tr:commandNavigationItem immediate="true"
							      text="#{foo.label}" action="#{foo.doAction}"/>							      
							  </f:facet>
							</tr:navigationPane>
	                                      <jsp:include page="switchers/messages.jspx"/>
							  							
                                    </tr:panelGroupLayout>   
			</tr:panelHorizontalLayout>


Here's my menu model:

<?xml version="1.0" encoding="iso-8859-1"?>
<menu xmlns="http://myfaces.apache.org/trinidad/menu">
	<groupNode id="msgs" idref="message" label="Error Messages" defaultFocustPath="true">		
		<itemNode id="message" label="Messages" action="goToMessages" 
			focusViewId="/index.jspx"/>
		<itemNode id="help" label="Help Text" action="goToHelp"
			focusViewId="/index.jspx"/>
		<itemNode id="button" label="Buttons" action="goToButton"
			focusViewId="/index.jspx"/>
		<itemNode id="sound" label="Sounds" action="goToSound"
			focusViewId="/index.jspx" />
	</groupNode>
	<groupNode id="allcodes" label="AllCodes" idref="cat">
	<itemNode id="codes" label="All Codes" action="goToAllCodes"
			focusViewId="/index.jspx" />		
		<itemNode id="cat" label="Categories" action="goToCategies"
			focusViewId="/index.jspx" />
		<itemNode id="link" label="CodeLinks" action="goToLink"
			focusViewId="/index.jspx" />
	</groupNode>	
</menu>


My messages.jspx switcher is as follows: It just has a command on each facet to demonstrate the problem.

	
	<tr:switcher facetName="#{root_menu.navLabel}">
		  		<f:facet name="Messages">
		    		<tr:panelGroupLayout partialTriggers="cmd1" layout="vertical">
					     <tr:commandButton id="cmd1" text="Enter"  partialSubmit="true"	/>
					</tr:panelGroupLayout>
		  		</f:facet>
				<f:facet name="Help Text">
		    		<tr:panelGroupLayout partialTriggers="cmd2" layout="vertical">                         
 							<tr:commandButton id="cmd2" text="Enter"  partialSubmit="true"/>
					</tr:panelGroupLayout>
		  		</f:facet>
		        <f:facet name="Buttons">
		           <tr:panelGroupLayout partialTriggers="cmd3" layout="vertical">                         
                         <tr:commandButton id="cmd3" text="Enter" partialSubmit="true"/>
					</tr:panelGroupLayout>
		  		</f:facet>
		  		<f:facet name="Sounds">
		    		<tr:panelGroupLayout partialTriggers="cmd4" layout="vertical">
                         <tr:commandButton id="cmd4" text="Enter" partialSubmit="true"/>
					</tr:panelGroupLayout>
		  		</f:facet>
				<f:facet name="All Codes">
		    		<tr:panelGroupLayout partialTriggers="cmd11" layout="vertical">
					     <tr:commandButton id="cmd11" text="Enter"  partialSubmit="true"/>
					</tr:panelGroupLayout>
		  		</f:facet>
				<f:facet name="Categories">
		    		<tr:panelGroupLayout partialTriggers="cmd12" layout="vertical">
                        <tr:commandButton id="cmd12" text="Enter"  partialSubmit="true"/>
					</tr:panelGroupLayout>
		  		</f:facet>
		        <f:facet name="CodeLinks">
		           <tr:panelGroupLayout partialTriggers="cmd13" layout="vertical">                         
                         <tr:commandButton id="cmd13" text="Enter" partialSubmit="true"/>
					</tr:panelGroupLayout>
		  		</f:facet>
				
			</tr:switcher>

I use a MenuModelBean to drive all of this. This is similar to the example XMLMenuModel in the Trinidad developer's guide.

          public class MenuModelBean extends XMLMenuModel{
	
	public String getGroupLabel(){
		List list = getNodesFromFocusPath(false);
		return (String)list.get(list.size()-1);
	}
	public String getNavLabel(){
		List list = getNodesFromFocusPath(true);
		return (String)list.get(list.size()-1);
	}
    public List getNodesFromFocusPath(boolean itemsOnly){
      ArrayList focusPath = (ArrayList)this.getFocusRowKey();
      return getNodesFromFocusPath(focusPath, itemsOnly);	      
    } 
    
    public List getNodesFromFocusPath(ArrayList focusPath, boolean itemsOnly){
	      
	      
	      if (focusPath == null || focusPath.size() == 0)
	        return null;

	      // Clone the focusPath cause we remove elements
	      ArrayList fp = (ArrayList) focusPath.clone();
	  
	      // List of nodes to return
	      List nodeList = new ArrayList<Object>();
	  
	      // Convert String rowkey to int and point to the
	      // node (row) corresponding to this index
	      int targetNodeIdx = (Integer)fp.get(0);
	      TreeModel tree = (TreeModel)this.getWrappedData();
	      
	      tree.setRowIndex(targetNodeIdx);

	      // Get the node
	      Object node = tree.getRowData();
	      String label = null;
	      if(node instanceof ItemNode){
	    	  label= ((ItemNode)node).getLabel();
	    	  if(itemsOnly)
	    		  nodeList.add(label);
	      }	  
	      else if (node instanceof GroupNode){
	    	  label= ((GroupNode)node).getLabel();
	    	  if(!itemsOnly)
	    		  nodeList.add(label);
	      }
	      
	    
	      
	      // Remove the 0th rowkey from the focus path
	      // leaving the remaining focus path
	      fp.remove(0);
	  
	      // traverse into children 
	      if (   fp.size() > 0
	          && tree.isContainer() 
	          && !tree.isContainerEmpty()
	         )
	      {
	        tree.enterContainer();
	  
	        // get list of nodes in remaining focusPath
	        List childList = getNodesFromFocusPath(fp, itemsOnly);
	  
	        // Add this list to the nodeList
	        nodeList.addAll(childList);
	  
	        tree.exitContainer();
	      }
	  
	      return nodeList;
	    } 
 }

Finally, here are the relevant entries in faces-config.xml:

 <managed-bean>
       <managed-bean-name>root_menu</managed-bean-name>
       <managed-bean-class>com.dylt.bean.MenuModelBean</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       <managed-property>
	      <property-name>source</property-name>
	      <property-class>java.lang.String</property-class>
	      <value>/WEB-INF/menu-metadata.xml</value>
      </managed-property>
     </managed-bean>
     
     <!-- context switcher -->
     <managed-bean>
       <managed-bean-name>tableSwitcher</managed-bean-name>
       <managed-bean-class>org.apache.myfaces.trinidad.component.UIXSwitcher</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       <managed-property>
	      <property-name>facetName</property-name>
	      <property-class>java.lang.String</property-class>
	      <value>#{root_menu.navLabel}</value>
      </managed-property>
     </managed-bean>
     
     <!-- menu navigation rules -->
     <navigation-rule>
    	 <navigation-case>
	      	<from-outcome>*</from-outcome>
	      	<to-view-id>/index.jspx</to-view-id>
	     </navigation-case>	     
	  </navigation-rule>