Andrew,
Sorry I am not very familar with TabChangeListener. This type of question is really more appropriate for the myfaces-user list. The developers watch that one too and one of our user's might be able to help you as well.
Having looked at this again, I've come to the conclusion that there is a problem with the TabChangeListenerTag. I don't think that the current implementation is at all useful. I think that instead of being given a classname to instantiate, it would far more useful if you could feed it a valueBinding to a listener.
Once you evaluate the binding to find a listener, there are a couple of problems with the naive approach of attaching it. However if you simply attach a listener which on process* re-evaluates the binding it should work.
I am not sure that I have completely thought out this problem though. So any thoughts?
Thanks, andy
(I attach a patch to that shows this behaviour. I've changed the attribute of the TabChangeListenerTag to value. Unfortunately I don't know how to create a context patch that will create a file, so add ValueBindingTabChangeListener to the same directory as the tag.)
-- Andrew Thornton [EMAIL PROTECTED]
***
src/components/org/apache/myfaces/custom/tabbedpane/TabChangeListenerTag.java
Tue Mar 15 10:13:51 2005
---
src/components/org/apache/myfaces/custom/tabbedpane/TabChangeListenerTag.java
Wed Oct 13 12:50:58 2004
***************
*** 51,57 ****
public class TabChangeListenerTag extends TagSupport
{
! private String value = null;
public TabChangeListenerTag()
--- 51,57 ----
public class TabChangeListenerTag extends TagSupport
{
! private String type = null;
public TabChangeListenerTag()
***************
*** 59,75 ****
}
! public void setValue(String value)
{
! this.value = value;
}
public int doStartTag() throws JspException
{
! if (value == null)
{
! throw new JspException("value attribute not set");
}
//Find parent UIComponentTag
--- 59,75 ----
}
! public void setType(String type)
{
! this.type = type;
}
public int doStartTag() throws JspException
{
! if (type == null)
{
! throw new JspException("type attribute not set");
}
//Find parent UIComponentTag
***************
*** 86,108 ****
if (component instanceof HtmlPanelTabbedPane)
{
String className;
! if (UIComponentTag.isValueReference(value))
{
FacesContext facesContext =
FacesContext.getCurrentInstance();
! ValueBinding valueBinding =
facesContext.getApplication().createValueBinding(value);
! Object boundValue = valueBinding.getValue(facesContext);
! if (boundValue instanceof TabChangeListener) {
! ((HtmlPanelTabbedPane)
component).addTabChangeListener(new ValueBindingTabChangeListener(value));
! } else {
! TabChangeListener listener = (TabChangeListener)
ClassUtils.newInstance((String)boundValue);
! ((HtmlPanelTabbedPane)
component).addTabChangeListener(listener);
! }
} else
{
! className = value;
TabChangeListener listener = (TabChangeListener)
ClassUtils.newInstance(className);
((HtmlPanelTabbedPane)
component).addTabChangeListener(listener);
- }
} else
{
throw new JspException("Component " + component.getId() + "
is no HtmlPanelTabbedPane");
--- 86,102 ----
if (component instanceof HtmlPanelTabbedPane)
{
String className;
! if (UIComponentTag.isValueReference(type))
{
FacesContext facesContext =
FacesContext.getCurrentInstance();
! ValueBinding valueBinding =
facesContext.getApplication().createValueBinding(type);
! className = (String) valueBinding.getValue(facesContext);
} else
{
! className = type;
! }
TabChangeListener listener = (TabChangeListener)
ClassUtils.newInstance(className);
((HtmlPanelTabbedPane)
component).addTabChangeListener(listener);
} else
{
throw new JspException("Component " + component.getId() + "
is no HtmlPanelTabbedPane");
/* * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.myfaces.custom.tabbedpane;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.event.AbortProcessingException;
import java.io.Serializable;
/**
* ValueBindingTabChangeListener helper class that wraps a value-binding to a
* TabChangeListener, evaluating it on processTabChangeEvent.
*
* @author Andrew Thornton
*/
public class ValueBindingTabChangeListener implements TabChangeListener,
Serializable
{
private String value;
public ValueBindingTabChangeListener()
{
}
public ValueBindingTabChangeListener(String value)
{
this.value = value;
}
public void setValue(String value)
{
this.value = value;
}
public String getValue()
{
return this.value;
}
public void processTabChange(TabChangeEvent event) throws
AbortProcessingException
{
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueBinding valueBinding =
facesContext.getApplication().createValueBinding(value);
TabChangeListener listener = (TabChangeListener)
valueBinding.getValue(facesContext);
listener.processTabChange(event);
}
}
