Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
License Agreement. Rich Faces - Natural Ajax for Java Server Faces (JSF) Copyright (C) 2007 Exadel, Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 package org.richfaces.view.facelets;
 import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.event.AbortProcessingException;
 import  javax.faces.event.FacesEvent;
 import  javax.faces.event.FacesListener;
 import  javax.faces.view.AttachedObjectHandler;
 import  javax.faces.view.facelets.ComponentHandler;
 import  javax.faces.view.facelets.FaceletContext;
 import  javax.faces.view.facelets.TagAttribute;
 import  javax.faces.view.facelets.TagAttributeException;
 import  javax.faces.view.facelets.TagConfig;
 import  javax.faces.view.facelets.TagException;
 import  javax.faces.view.facelets.TagHandler;

Aug 31, 2010
 public abstract class EventListenerHandler extends TagHandler implements AttachedObjectHandler {
     protected final TagAttribute binding;
     protected final String listenerType;
     public abstract static class LazyEventListener<L extends FacesListener> implements FacesListener, Serializable {
         private static final long serialVersionUID = 1L;
         protected final String type;
         protected final ValueExpression binding;
         protected LazyEventListener(String typeValueExpression binding) {
             this. = type;
             this. = binding;
         public void processEvent(FacesEvent eventthrows AbortProcessingException {
             FacesContext faces = FacesContext.getCurrentInstance();
             if (faces == null) {
             L instance = null;
             if (this. != null) {
                 instance = (L) .getValue(faces.getELContext());
             if (instance == null && this. != null) {
                 try {
                     instance = (L) TagHandlerUtils.loadClass(this.Object.class).newInstance();
                 } catch (Exception e) {
                     throw new AbortProcessingException("Couldn't Lazily instantiate EventListener"e);
                 if (this. != null) {
                     .setValue(faces.getELContext(), instance);
             if (instance != null) {
     public EventListenerHandler(TagConfig config) {
         this. = this.getAttribute("binding");
         TagAttribute type = this.getAttribute("type");
         if (type != null) {
             if (type.isLiteral()) {
                 try {
                     TagHandlerUtils.loadClass(type.getValue(), Object.class);
                 } catch (ClassNotFoundException e) {
                     throw new TagAttributeException(type"Couldn't qualify EventListener"e);
             } else {
                 throw new TagAttributeException(type"Must be a literal class name of type EventListener");
            this. = type.getValue();
        } else {
            this. = null;
    public void apply(FaceletContext ctx, UIComponent parentthrows IOException {
        // only process if it's been created
        if (parent == null || !ComponentHandler.isNew(parent)) {
        if (isEventSource(parent)) {
            applyAttachedObject(ctx.getFacesContext(), parent);
        } else if (UIComponent.isCompositeComponent(parent)) {
            // Allow the composite component to know about the target component.
        } else {
            throw new TagException(this."Parent does not match event source requirements: " + parent);
    public String getFor() {
        TagAttribute attr = this.getAttribute("for");
        return attr == null ? null : attr.getValue();
    public abstract boolean isEventSource(UIComponent comp);
New to GrepCode? Check out our FAQ X