コード例 #1
0
    public void processEvent(FacesEvent event) throws AbortProcessingException {

      FacesContext faces = FacesContext.getCurrentInstance();
      if (faces == null) {
        return;
      }

      L instance = null;
      if (this.binding != null) {
        instance = (L) binding.getValue(faces.getELContext());
      }
      if (instance == null && this.type != null) {
        try {
          instance = (L) TagHandlerUtils.loadClass(this.type, Object.class).newInstance();
        } catch (Exception e) {
          throw new AbortProcessingException("Couldn't Lazily instantiate EventListener", e);
        }
        if (this.binding != null) {
          binding.setValue(faces.getELContext(), instance);
        }
      }

      if (instance != null) {
        event.processListener(instance);
      }
    }
コード例 #2
0
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {

    // only process if it's been created
    if (parent == null || !ComponentHandler.isNew(parent)) {
      return;
    }

    if (isEventSource(parent)) {
      applyAttachedObject(ctx.getFacesContext(), parent);
    } else if (UIComponent.isCompositeComponent(parent)) {
      // Allow the composite component to know about the target component.
      TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
    } else {
      throw new TagException(
          this.tag, "Parent does not match event source requirements: " + parent);
    }
  }
コード例 #3
0
 public EventListenerHandler(TagConfig config) {
   super(config);
   this.binding = 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.listenerType = type.getValue();
   } else {
     this.listenerType = null;
   }
 }