incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Causevic, Dzenan" <dcause...@navisite.com>
Subject RE: ActionListener for navigation tabs
Date Fri, 27 Oct 2006 22:00:46 GMT
I use both actionListener (to set focus on selected tab, and set navigation case outcome corresponding
to this tab by detecting its id value) and action (to return outcome string stored in the
bean by actionListener) and navigation is okay now. I get moved to correct pages by clicking
on its tabs, HOWEVER now the tabs are not being selected correctly. I move to a right page
but the wrong tab is being selected. And it seems to be delayed by one click. Namely the focus
of selected tabs get on the one that I previously clicked on. Now I found out after some testing
that this happens because I am loading different jsp files every time I click on the tab.
If I reload the same jsp page (I set all tabs to point to the one same jsp page) tabs are
being selected correctly. This makes me think there is an issue with page scope and tab component.
Seems to me that every time I load different jsp page (they are all including common code
section for tabs), a new instance of tab component object is being created and it has no way
of tracking its state from the previous page. Shouldn't these tab component objects be STATIC
so that they retain their values across multiple pages. I mean shoudn't all different pages
be refferencing one same object instance created when the first page containing tab components
was loaded. And shouldn't all subsequent (different) jsp pages be still refferencing that
same object?

Am I missing something here? Is there a way to make every tab component object STATIC across
different jsp pages?


-----Original Message-----
From: Matt Cooper [mailto:matt.faces@gmail.com]
Sent: Mon 10/23/2006 4:05 PM
To: adffaces-user@incubator.apache.org
Subject: Re: ActionListener for navigation tabs
 
Hi,

Instead of using "actionListener", you may can use "action" like this:

<tr:commandNavigationItem text="More Info" action="guide.moreInfo"/>

or

<tr:commandNavigationItem text="More Info" action="#{
demoCommandNavigationItem.moreInfo}"/>

where #{demoCommandNavigationItem.moreInfo} is:

  public String moreInfo()
  {
    return "guide.moreInfo";
  }

Now, if you want to use actionListener for example to set more properties on
the bean, you can implement both an actionListener and an action.  If you
wanted a single bean for all of your 4 tabs, the actionListener can have
code to detect which tab was clicked, save off that info, then in the
action, you can return a particular action string for the particular tab
that was clicked.

Regards,
Matt

On 10/23/06, Causevic, Dzenan <dcausevic@navisite.com> wrote:
>
>
> I am trying to have tabs navigation on the top of my page but I need to
> set up ActionListener correctly so that it changes focus of selected tabs
> correctly and also to move you to a different page when clicked on certain
> tab. I used the ActionListener provided with the demo application (I
> decompiled it with jad utility to obtain the source code)
> $TRINIDAD_HOME/WEB-INF/classes/org/apache/myfaces/trinidaddemo/DemoCommandNavigationItemBean.class
> but it only serves to change the focus as you select tabs. It does not move
> you to a different page at the same time. It works the same way in the demo,
> and on my own page. What needs to be added to the
> DemoCommandNavigationItemBean.java source code below to also allow you to
> move to a different page?
>
> // Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
> // Jad home page: http://www.geocities.com/kpdus/jad.html
> // Decompiler options: packimports(3)
> // Source File Name:   DemoCommandNavigationItemBean.java
>
> package org.apache.myfaces.trinidaddemo;
>
> import java.io.PrintStream;
> import java.util.Iterator;
> import java.util.List;
> import javax.faces.component.UIComponent;
> import javax.faces.event.ActionEvent;
> import org.apache.myfaces.trinidad.bean.FacesBean;
> import org.apache.myfaces.trinidad.component.UIXCommand;
> import org.apache.myfaces.trinidad.component.UIXNavigationHierarchy;
> import org.apache.myfaces.trinidad.context.RequestContext;
>
> public class DemoCommandNavigationItemBean
> {
>
>     public DemoCommandNavigationItemBean()
>     {
>     }
>
>     public void navigationItemAction(ActionEvent event)
>     {
>         UIComponent actionItem = event.getComponent();
>         UIComponent parent;
>         for(parent = actionItem.getParent(); !(parent instanceof
> UIXNavigationHierarchy);)
>         {
>             parent = parent.getParent();
>             if(parent == null)
>             {
>                 System.err.println("Unexpected component hierarchy, no
> UIXNavigationHierarchy found.");
>                 return;
>             }
>         }
>
>         List children = parent.getChildren();
>         Iterator i$ = children.iterator();
>         do
>         {
>             if(!i$.hasNext())
>                 break;
>             UIXCommand child = (UIXCommand)i$.next();
>             FacesBean childFacesBean = child.getFacesBean();
>             org.apache.myfaces.trinidad.bean.FacesBean.Type type =
> childFacesBean.getType();
>             org.apache.myfaces.trinidad.bean.PropertyKey selectedKey =
> type.findKey("selected");
>             if(selectedKey != null)
>                 childFacesBean.setProperty(selectedKey, Boolean.valueOf(child
> == actionItem));
>         } while(true);
>         RequestContext adfContext = RequestContext.getCurrentInstance();
>         adfContext.addPartialTarget(parent);
>     }
> }
>
> This is code from my JSP page that implements trinidad tab navigation
> components:
>
> <tr:navigationPane hint="tabs">
>       <tr:commandNavigationItem text="Home" actionListener="#{
> demoCommandNavigationItem.navigationItemAction}" selected="true"/>
>       <tr:commandNavigationItem text="Code of Conduct" actionListener="#{
> demoCommandNavigationItem.navigationItemAction}"/>
>       <tr:commandNavigationItem text="Personal Info" actionListener="#{
> demoCommandNavigationItem.navigationItemAction}"/>
>       <tr:commandNavigationItem text="More Info" actionListener="#{
> demoCommandNavigationItem.navigationItemAction}"/>
> </tr:navigationPane>
>
> demoCommandNavigationItem is registered in faces-managed-beans.xmlcorrectly as following:
>   <managed-bean>
>       <managed-bean-name>demoCommandNavigationItem</managed-bean-name>
>       <managed-bean-class>
> com.navisite.view.beans.DemoCommandNavigationItemBean</managed-bean-class>
>       <managed-bean-scope>session</managed-bean-scope>
>   </managed-bean>
>
> faces-navigation.xml is as following:
>     <navigation-rule>
>         <navigation-case>
>             <from-outcome>guide.login</from-outcome>
>             <to-view-id>/jsp/registration/loginJSF.jsp</to-view-id>
>             <redirect/>
>         </navigation-case>
>         <navigation-case>
>             <from-outcome>guide.codeOfConduct</from-outcome>
>
>             <to-view-id>/jsp/registration/codeOfConductJSF.jsp</to-view-id>
>             <redirect/>
>         </navigation-case>
>         <navigation-case>
>             <from-outcome>guide.personalInfo</from-outcome>
>             <to-view-id>/jsp/registration/personalInfoJSF.jsp</to-view-id>
>             <redirect/>
>         </navigation-case>
>         <navigation-case>
>             <from-outcome>guide.moreInfo</from-outcome>
>             <to-view-id>/jsp/registration/moreInfoJSF.jsp</to-view-id>
>             <redirect/>
>         </navigation-case>
>     </navigation-rule>
>
>


Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message