Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.richfaces.view.facelets;
  
  
  import javax.el.ELContext;
  import  javax.faces.component.UIComponent;
 import  javax.faces.context.FacesContext;
 import  javax.faces.event.AbortProcessingException;
 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;
 
 import  org.richfaces.event.TreeSelectionChangeEvent;
 import  org.richfaces.event.TreeSelectionChangeListener;
 import  org.richfaces.event.TreeSelectionChangeSource;
 
 public class TreeSelectionChangeListenerHandler extends TagHandler {
 
     @SuppressWarnings("serial")
     public static final class LazyListener implements TreeSelectionChangeListener, Serializable {
 
         private final String type;
 
         private final ValueExpression binding;
 
         public LazyListener(String typeValueExpression binding) {
             this. = type;
             this. = binding;
         }
 
         public void processTreeSelectionChange(org.richfaces.event.TreeSelectionChangeEvent eventthrows AbortProcessingException {
             TreeSelectionChangeListener instance = null;
             FacesContext faces = FacesContext.getCurrentInstance();
             if (faces == null) {
                 return;
             }
 
             if (this. != null) {
                 instance = (TreeSelectionChangeListener) .getValue(faces.getELContext());
             }
 
             if (instance == null && this. != null) {
                 try {
                     ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                     if (null == classLoader) {
                         classLoader = TreeSelectionChangeListener.class.getClassLoader();
                     }
                     instance = classLoader.loadClass(this.).asSubclass(TreeSelectionChangeListener.class).newInstance();
                 } catch (Exception e) {
                     throw new AbortProcessingException("Couldn't lazily instantiate TreeSelectionChangeListener"e);
                 }
 
                 if (this. != null) {
                     .setValue(faces.getELContext(), instance);
                 }
             }
 
             if (instance != null) {
                 instance.processTreeSelectionChange(event);
             }
         }
     }
 
     @SuppressWarnings("serial")
     public static final class MethodExpressionListener implements TreeSelectionChangeListener, Serializable {
 
         private MethodExpression methodExpression;
 
         public MethodExpressionListener(MethodExpression methodExpression) {
             super();
             this. = methodExpression;
         }
 
         public void processTreeSelectionChange(org.richfaces.event.TreeSelectionChangeEvent actionEventthrows AbortProcessingException {
             if (actionEvent == null) {
                 throw new NullPointerException();
             }
             FacesContext context = FacesContext.getCurrentInstance();
             ELContext elContext = context.getELContext();
             try {
                 .invoke(elContextnew Object[] { actionEvent });
             } catch (Exception e) {
                 new AbortProcessingException(e);
             }
         }
     }
 
     private TagAttribute binding;
 
     private String listenerType;
 
     private TagAttribute listenerMethod;
    public TreeSelectionChangeListenerHandler(TagConfig config) {
        super(config);
        this. = this.getAttribute("binding");
        TagAttribute type = this.getAttribute("type");
        if (type != null) {
            if (!type.isLiteral()) {
                throw new TagAttributeException(type"Must be a literal class name of type TreeSelectionChangeListener");
            } else {
                // test it out
            }
            this. = type.getValue();
        } else {
            this. = null;
        }
        this. = this.getAttribute("listener");
        if (this. != null && this. != null) {
            throw new TagException(this."Attributes 'listener' and 'binding' cannot be used simultaneously");
        }
        if (this. != null && this. != null) {
            throw new TagException(this."Attributes 'listener' and 'type' cannot be used simultaneously");
        }
    }
    /*
     * (non-Javadoc)
     * 
     * @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext,
     * javax.faces.component.UIComponent)
     */
    public void apply(FaceletContext ctx, UIComponent parentthrows IOException {
        if (null != parent && ComponentHandler.isNew(parent)) {
            if (!(parent instanceof TreeSelectionChangeSource)) {
                throw new TagException(this."Parent is not of type TreeSelectionChangeSource, type is: " + parent);
            }
            TreeSelectionChangeSource as = (TreeSelectionChangeSource) parent;
            if (this. != null) {
                MethodExpression listenerMethodExpression =
                    this..getMethodExpression(ctx.new Class<?>[] { org.richfaces.event.TreeSelectionChangeEvent.class });
                as.addTreeSelectionChangeListener(new MethodExpressionListener(listenerMethodExpression));
            } else {
                ValueExpression b = null;
                if (this. != null) {
                    b = this..getValueExpression(ctx, TreeSelectionChangeListener.class);
                }
                TreeSelectionChangeListener listener = new LazyListener(this.b);
                as.addTreeSelectionChangeListener(listener);
            }
        }
    }
New to GrepCode? Check out our FAQ X