There is no way to do this out of the box. You need to create a tag handler that fills the resposibility of the UpdateActionListenerTag. I have created one. The code is attached. Just change the packages for your needs

The XML to register this is:
    <tag>
        <tag-name>updateActionListener</tag-name>
        <handler-class>org.bethanyefree.taghandlers.TomahawkUpdateActionListenerHandler</handler-class>
    </tag>

Just add that to your facelet configuration file for the tomahawk components.

On 10/3/05, Denis Parhomenko <[EMAIL PROTECTED]> wrote:
Hi

I want use UpdateActionListener with facelets, but facelets told me that

com.sun.facelets.tag.TagException: /pages/admin/locations/edit.jsp @59,116 <t:updateActionListener> Tag Library supports namespace: http://myfaces.apache.org/tomahawk, but no tag was defined for name: updateActionListener
    at com.sun.facelets.compiler.CompilationManager.pushTag(CompilationManager.java:155)
    at com.sun.facelets.compiler.SAXCompiler$CompilationHandler.startElement(SAXCompiler.java:175)

As I understand i need add somthing to tomahawk.taglib.xml, but i don't know  what

Deniss

/**
 * 
 */
package org.bethanyefree.taghandlers;

import java.io.IOException;

import javax.el.ELException;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.component.ActionSource;
import javax.faces.component.UIComponent;
import javax.faces.convert.Converter;
import javax.faces.el.ValueBinding;
import javax.faces.event.ActionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.custom.updateactionlistener.UpdateActionListener;

import com.sun.facelets.FaceletContext;
import com.sun.facelets.FaceletException;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.TagConfig;
import com.sun.facelets.tag.TagHandler;
import com.sun.facelets.tag.jsf.ComponentConfig;

/**
 * @author andrew
 *
 */
public class TomahawkUpdateActionListenerHandler
	extends TagHandler
{
	private static Log logger = LogFactory.getLog(TomahawkUpdateActionListenerHandler.class);
	
	private TagAttribute converterAttr;
	private TagAttribute propertyAttr;
	private TagAttribute valueAttr;
	
	/**
	 * @param config
	 */
	public TomahawkUpdateActionListenerHandler(ComponentConfig config)
	{
		this((TagConfig)config);
	}
	
	/**
	 * @param config
	 */
	public TomahawkUpdateActionListenerHandler(TagConfig config)
	{
		super(config);
		valueAttr = getRequiredAttribute("value");
		propertyAttr = getRequiredAttribute("property");
		converterAttr = getAttribute("converter");
	}

	/**
	 * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext, javax.faces.component.UIComponent)
	 */
	public void apply(FaceletContext ctx, UIComponent parent)
		throws IOException, FacesException, FaceletException, ELException
	{
		logger.error("Apply called. Component: " + parent);
		ActionSource actionSource = (ActionSource)parent;
		
		if (sourceHasProperty(actionSource))
			return;
		
		UpdateActionListener al = new UpdateActionListener();
		
		if (converterAttr != null)
			al.setConverter((Converter)converterAttr.getObject(ctx));
		
		Application app = ctx.getFacesContext().getApplication();
		ValueBinding vb = app.createValueBinding(valueAttr.getValue());
		al.setValueBinding(vb);
		vb = app.createValueBinding(propertyAttr.getValue());
		al.setPropertyBinding(vb);
		actionSource.addActionListener(al);
	}
	
	private boolean sourceHasProperty(ActionSource source)
	{
		for (ActionListener listener : source.getActionListeners())
		{
			if (listener instanceof UpdateActionListener == false) continue;
			UpdateActionListener al = (UpdateActionListener)listener;
			if (al.getPropertyBinding().getExpressionString().equals(
				this.propertyAttr.getValue()))
			{
				logger.debug("Action listener already has a listener for " +
					this.propertyAttr.getValue());
				return true;
			}
		}
		logger.debug("Action listener for property is not present. Property: " +
			this.propertyAttr.getValue());
		return false;
	}
}

Reply via email to