myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Silverman, Glenn" <>
Subject How can I create a session scoped Trinidad menu model
Date Thu, 31 Jul 2008 21:05:34 GMT
I need a session-scoped menu model but the documentation says I can't, and that creates a problem
whenever I click on a button to do something when I'm not on the first tab of the menu. Here's
my code...
I have a trinidad switcher control managed by a commandNavigationItem control.

			<tr:navigationPane id="navPaneA" level="1" value="#{root_menu}" var="foo">
				<f:facet name="nodeStamp">
					<tr:commandNavigationItem id="navItemA" text="#{foo.label}"

			<tr:switcher facetName="#{root_menu.navLabel}" defaultFacet="Messages" >
		  		<f:facet name="Messages">
		    		<tr:panelGroupLayout layout="vertical">
						<jsp:include page="../editors/errormessages.jspx"/>
				<f:facet name="Help Text">
		    		<tr:panelGroupLayout layout="vertical">
						<jsp:include page="../editors/help.jspx"/>
		        <f:facet name="Buttons">
		           <tr:panelGroupLayout layout="vertical">
						<jsp:include page="../editors/buttons.jspx"/>		
		  		<f:facet name="Sounds">
		    		<tr:panelGroupLayout layout="vertical">
						<jsp:include page="../editors/sounds.jspx"/>		

And a menu model:

	<menu xmlns="">
		<groupNode id="msgs" idref="message" label="Error Messages" defaultFocustPath="true">
			<itemNode id="message" label="Messages" action="goToMessages" 
			<itemNode id="help" label="Help Text" action="goToHelp"
			<itemNode id="button" label="Buttons" action="goToButton"
			<itemNode id="sound" label="Sounds" action="goToSound"
		<groupNode id="allcodes" label="AllCodes" idref="cat">		
			<itemNode id="cat" label="Categories" action="goToCategory"
				focusViewId="/index.jspx" />
			<itemNode id="link" label="CodeLinks" action="goToLink"
				focusViewId="/index.jspx" />

which is defined in faces-config.xml as a managed bean:


Here, MenuModelBean just extends XMLMenuModel as follows (This is
similar to the example in the Trinidad Developer 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();

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

Here's the problem: If I'm on one of the facet pages other than the first one, clicking
on any command button or link always takes me back to the first facet. If I use
partialSubmit and partialTriggers to try to limit page refresh to a particular page
element, the behavior is even more bizarre. If I click on a tab to change facets, the
first command button or link click works as expected, but any subsequent clicks assume
I am on the first facet page and won't update the facet page I'm on at all. 

Here's an example page, the help.jspx in the second facet:

	jsp:root xmlns:jsp="" version="2.0"
	< contentType="text/html;charset=utf-8" />
		<f:subview id="helpWrapperA">
			<tr:table id="helpTableA" var="hlp" value="#{helpBean.list}" partialTriggers="helpEditLink">
				<tr:column headerText="Id">
					<tr:outputText value="#{hlp.helpId}" />
				<tr:column headerText="Message">
					<tr:commandLink id="helpEditLink" text="#{hlp.text}"
						immediate="true" partialSubmit="true">
						<tr:setActionListener from="#{hlp}"
							to="#{pageFlowScope.helpDetail}" />
        <tr:showDetail undisclosedText="Show Detail" disclosedText="Hide Detail"> 
	        <f:subview id="helpWrapperB">
				<tr:panelFormLayout rows="2" 
					<tr:outputText value="ID:" />
					<tr:outputText value="Text:" />
					<tr:outputText value="#{pageFlowScope.helpDetail.helpId}" />
					<tr:inputText value="#{pageFlowScope.helpDetail.text}"/>	

Could this behavior be the result of the fact that the scope for the menu model must be "request"
? If so, then every subsequent
"request" will always go to, or assume I'm on,  the default tab.  How can I change this?

Glenn Silverman

View raw message