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 <[EMAIL PROTECTED]> 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>