myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Robinson" <andrew.rw.robin...@gmail.com>
Subject Re: How can I create a session scoped Trinidad menu model
Date Mon, 04 Aug 2008 17:02:17 GMT
Why do you want it to be session scoped? What advantage would that
have for you? The architecture is really coded for only one use case,
so trying to use it outside of how the Oracle developer thought you
would use it is really ugly. It probably needs a re-write at some
point.

-Andrew

On Mon, Aug 4, 2008 at 10:40 AM, Silverman, Glenn <GSilverman@dylt.com> wrote:
> I'm still in a quandry. I tried using ChildPropertyMenuModel and that turns out
> to be a nightmare just configuring in faces-config.xml, and, I could not get
> it to work using the "level" attribute on NavigationPane control to retrieve the children
nodes.
>
> So, I'm back to trying to get XMLMenuModel to work. Does anyone know why you can't create
it in
> session scope and/or, is there a work-around?
>
> Here's simple web app anyone can easily set up that demonstrates the problem.
>
> menu-metadata.xml:
> <menu xmlns="http://myfaces.apache.org/trinidad/menu">
>  <itemNode id="gin1" label="Global 0"
>              focusViewId="/index.jspx">
>    <itemNode id="in1" label="Tab 1" destination="index.jspx"
>              focusViewId="/index.jspx">
>    </itemNode>
>    <itemNode id="in2" label="Tab 2" destination="index.jspx"
>                focusViewId="/index.jspx"/>
>  </itemNode>
>  <itemNode id="gin1" label="Global 1"
>            destination="index.jspx"
>            focusViewId="/index.jspx"/>
>  <itemNode id="gin2" label="Global 2"
>            destination="index.jspx" focusViewId="/index.jspx"/>
> </menu>
>
>
> Faces-config.xml:
> <faces-config
>    xmlns="http://java.sun.com/xml/ns/javaee"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
>    version="1.2">
>  <application>
>    <!-- Use the Trinidad RenderKit -->
>    <default-render-kit-id>org.apache.myfaces.trinidad.core</default-render-kit-id>
>   </application>
>
>   <!-- managed bean menu model -->
>     <managed-bean>
>       <managed-bean-name>root_menu</managed-bean-name>
>       <managed-bean-class>org.apache.myfaces.trinidad.model.XMLMenuModel</managed-bean-class>
>       <managed-bean-scope>request</managed-bean-scope>
>       <managed-property>
>         <property-name>source</property-name>
>         <value>/WEB-INF/menu-metadata.xml</value>
>       </managed-property>
>     </managed-bean>
> </faces-config>
>
>
> Index.jspx
> <?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
> <jsp:root version="1.2"
>  xmlns:jsp="http://java.sun.com/JSP/Page"
>  xmlns:f="http://java.sun.com/jsf/core"
>  xmlns:tr="http://myfaces.apache.org/trinidad">
>  <jsp:directive.page contentType="text/html;charset=utf-8"/>
>  <f:view>
>    <tr:document title="MenuModel Demo">
>      <tr:form>
>       <tr:page var="foo" value="#{root_menu}">
>          <f:facet name="branding">
>            <tr:panelGroupLayout layout="vertical">
>               <tr:outputText value="MenuModel"/>
>            </tr:panelGroupLayout>
>          </f:facet>
>          <tr:panelHorizontalLayout valign="top" >
>            <f:facet name="separator">
>                        <tr:spacer width="10" height="1"/>
>                        </f:facet>
>           <tr:navigationTree var="foo" value="#{root_menu}">
>                                <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
>                                                          text="#{foo.label}"
>                                                          action="#{foo.doAction}"/>
>                                              </f:facet>
>                            </tr:navigationPane>
>                    <tr:panelHorizontalLayout valign="top">
>                        <tr:commandButton id="myButton" text="Ok" actionListener="#{myButton.doSomething}"/>
>                        <tr:outputText value="#{root_menu.focusRowKey}" />
>                    </tr:panelHorizontalLayout>
>                </tr:panelGroupLayout>
>          </tr:panelHorizontalLayout>
>        </tr:page>
>      </tr:form>
>    </tr:document>
>  </f:view>
> </jsp:root>
>
>
> Index.jspx just has a left-side tree pane that uses the menu and a panel layout that
uses the level 1 menu
> items as tabs. The page has a single button that when clicked, shows the focusRowKey
of the selected menu
> item.
>
> Clicking the button twice always takes you back to focusRowKey=[0] the first menu item,
which in
> this case is the itemNode, "Global 0", no matter what tab you selected. That's because
the menu is
> in request scope. I've tried everything I can think of to capture the selected node in
session and
> even pageFlowScope. but nothing seems to work.
>
> Has anyone been able to solve this issue. If not, then I will have to go back to Ajax4jsf,
or some other
> JSF implementation to use in my apps.
>
> Glenn...
>
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com]
> Sent: Thursday, July 31, 2008 4:24 PM
> To: MyFaces Discussion
> Subject: Re: How can I create a session scoped Trinidad menu model
>
>
> My personal opinion would be to not use it. It really gave me
> heartburn when I attempted to use it. I would recommend using
> ChildPropertyMenuModel instead and if you want to use XML, use the
> commons digester with it. That is just my opinion though.
>
> BTW, I think it really is application scoped in practice, as it uses
> one shared model, so there really isn't any state to save (like in the
> session). The architecture of it is very odd and a bit broken (you can
> only have one menu model on a page for example).
>
> -Andrew
>
> On Thu, Jul 31, 2008 at 3:46 PM, Silverman, Glenn <GSilverman@dylt.com> wrote:
>> Are there any examples available of using XMLMenuModel. The
>> Trinidad demo apps use ProcessMenuModel and that, apparently, can
>> be session scoped, so it doen't help me.
>>
>> Glenn Silverman
>>
>> -----Original Message-----
>> From: Zigc Junk [mailto:zigcjunk@gmail.com]
>> Sent: Thursday, July 31, 2008 2:23 PM
>> To: MyFaces Discussion
>> Subject: Re: How can I create a session scoped Trinidad menu model
>>
>>
>> Did u try to change from request to session? Since your bean is
>> request scoped, every request will create a new instance of the bean,
>> so does its property.
>>
>> regard
>>
>> Bill
>>
>> On Thu, Jul 31, 2008 at 4:05 PM, Silverman, Glenn <GSilverman@dylt.com> wrote:
>>> 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}"
>>>                                                 action="#{foo.doAction}"/>
>>>                                 </f:facet>
>>>                         </tr:navigationPane>
>>>
>>>                         <tr:switcher facetName="#{root_menu.navLabel}"
>>> defaultFacet="Messages" >
>>>                                 <f:facet name="Messages">
>>>                                 <tr:panelGroupLayout layout="vertical">
>>>                                                 <jsp:include
>>> page="../editors/errormessages.jspx"/>
>>>                                         </tr:panelGroupLayout>
>>>                                 </f:facet>
>>>                                 <f:facet name="Help Text">
>>>                                 <tr:panelGroupLayout layout="vertical">
>>>                                                 <jsp:include
>>> page="../editors/help.jspx"/>
>>>                                         </tr:panelGroupLayout>
>>>                                 </f:facet>
>>>                         <f:facet name="Buttons">
>>>                            <tr:panelGroupLayout layout="vertical">
>>>                                                 <jsp:include
>>> page="../editors/buttons.jspx"/>
>>>                                         </tr:panelGroupLayout>
>>>                                 </f:facet>
>>>                                 <f:facet name="Sounds">
>>>                                 <tr:panelGroupLayout layout="vertical">
>>>                                                 <jsp:include
>>> page="../editors/sounds.jspx"/>
>>>                                         </tr:panelGroupLayout>
>>>                                 </f:facet>
>>>                         </tr:switcher>
>>>
>>> And a menu model:
>>>
>>>         <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="cat" label="Categories"
>>> action="goToCategory"
>>>                                 focusViewId="/index.jspx" />
>>>                         <itemNode id="link" label="CodeLinks"
>>> action="goToLink"
>>>                                 focusViewId="/index.jspx" />
>>>                 </groupNode>
>>>         </menu>
>>>
>>> which is defined in faces-config.xml as a managed bean:
>>>
>>>       <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>
>>>
>>> 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();
>>>
>>>               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;
>>>             }
>>>       )
>>>
>>> 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="http://java.sun.com/JSP/Page" version="2.0"
>>>                 xmlns:f="http://java.sun.com/jsf/core"
>>>                 xmlns:tr="http://myfaces.apache.org/trinidad">
>>>         <jsp:directive.page 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>
>>>                                 <tr:column headerText="Message">
>>>                                         <tr:commandLink id="helpEditLink"
>>> text="#{hlp.text}"
>>>                                                 immediate="true"
>>> partialSubmit="true">
>>>                                                 <tr:setActionListener
>>> from="#{hlp}"
>>>
>>> to="#{pageFlowScope.helpDetail}" />
>>>                                         </tr:commandLink>
>>>                                 </tr:column>
>>>                         </tr:table>
>>>         </f:subview>
>>>         <tr:separator/>
>>>         <tr:showDetail undisclosedText="Show Detail" disclosedText="Hide
>>> Detail">
>>>                 <f:subview id="helpWrapperB">
>>>                                 <tr:panelFormLayout rows="2"
>>>
>>> partialTriggers=":::helpWrapperA:helpTableA:helpEditLink">
>>>                                         <tr:outputText value="ID:" />
>>>                                         <tr:outputText value="Text:" />
>>>                                         <tr:outputText
>>> value="#{pageFlowScope.helpDetail.helpId}" />
>>>                                         <tr:inputText
>>> value="#{pageFlowScope.helpDetail.text}"/>
>>>                                 </tr:panelFormLayout>
>>>                     </f:subview>
>>>                 </tr:showDetail>
>>>         </jsp:root>
>>>
>>> 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
>>>
>>>
>>
>>
>
>

Mime
View raw message