incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Causevic, Dzenan" <dcause...@navisite.com>
Subject actionListener for navigation tabs
Date Mon, 30 Oct 2006 14:22:16 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?

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


This is code from my JSP page that implements trinidad tab navigation components:

<tr:navigationPane hint="tabs">
      <tr:commandNavigationItem id="login" text="Home" actionListener="#{commandNavigationItem.navigationItemAction}"
action="#{navigationCaseBean.getCaseValue}" selected="true"/>
      <tr:commandNavigationItem id="codeOfCond" text="Code of Conduct" actionListener="#{commandNavigationItem.navigationItemAction}"
action="#{navigationCaseBean.getCaseValue}"/>
      <tr:commandNavigationItem id="personalInfo" text="Personal Info" actionListener="#{commandNavigationItem.navigationItemAction}"
action="#{navigationCaseBean.getCaseValue}"/>
      <tr:commandNavigationItem id="moreInfo" text="More Info" actionListener="#{commandNavigationItem.navigationItemAction}"
action="#{navigationCaseBean.getCaseValue}"/>
</tr:navigationPane>

faces-managed-beans.xml is as following:

  <managed-bean>
      <managed-bean-name>commandNavigationItem</managed-bean-name>
      <managed-bean-class>com.navisite.view.beans.CommandNavigationItemBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>
  <managed-bean>
      <managed-bean-name>navigationCaseBean</managed-bean-name>
      <managed-bean-class>com.navisite.view.beans.NavigationCaseBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
  </managed-bean>

actionListener CommandNavigationItemBean.java:

import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.component.UIComponent;
import javax.faces.event.ActionEvent;
import org.apache.myfaces.trinidad.bean.FacesBean;
import org.apache.myfaces.trinidad.bean.PropertyKey;
import org.apache.myfaces.trinidad.component.UIXCommand;
import org.apache.myfaces.trinidad.component.UIXNavigationHierarchy;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.bean.FacesBean.Type;

/**
 *
 * @author dcausevic
 */
public class CommandNavigationItemBean {
    
    /** Creates a new instance of CommandNavigationItemBean */
    public CommandNavigationItemBean() {
    }
    
    public void navigationItemAction(ActionEvent event)
    {
        UIComponent actionItem = event.getComponent();
        
        NavigationCaseBean navCase = new NavigationCaseBean();        
        if(actionItem.getAttributes().containsValue("login")){
            navCase.setCaseValue("guide.login");
        } else if (actionItem.getAttributes().containsValue("codeOfCond")){
            navCase.setCaseValue("guide.codeOfConduct");
        } else if (actionItem.getAttributes().containsValue("personalInfo")){
            navCase.setCaseValue("guide.personalInfo");
        } else if (actionItem.getAttributes().containsValue("moreInfo")){
            navCase.setCaseValue("guide.moreInfo");        
        }
        
        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();
            Type type = childFacesBean.getType();
            PropertyKey selectedKey = type.findKey("selected");            
            if(selectedKey != null)
                childFacesBean.setProperty(selectedKey, Boolean.valueOf(child == actionItem));
           
        } while(true);
        RequestContext adfContext = RequestContext.getCurrentInstance();
        adfContext.addPartialTarget(parent);
    } 
}


action bean NavigationCaseBean.java:

/**
 *
 * @author dcausevic
 */
public class NavigationCaseBean {
    
    /** Creates a new instance of NavigationCaseBean */
    public NavigationCaseBean() {
    }

    private static String caseValue;

    public void setCaseValue(String caseValue) {
        this.caseValue = caseValue;
    }

    public String getCaseValue() {
        return caseValue;
    }    
}

faces-navigation.xml:

    <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/alternative (inline, None, 0 bytes)
View raw message