protected void doDecode(FacesContext facesContext, UIComponent uiComponent) {

    // super.decode must not be called, because value is handled here
    if (isSubmitted(facesContext, uiComponent)) {
      ActionEvent event;
      event = new ActionEvent(uiComponent);
      uiComponent.queueEvent(event);
      uiComponent.queueEvent(new AjaxEvent(uiComponent));
      // Check areas for processing
      if (uiComponent instanceof AjaxComponent) {
        AjaxComponent ajaxComponent = (AjaxComponent) uiComponent;
        Set<String> toProcess = AjaxRendererUtils.asSet(ajaxComponent.getProcess());
        if (null != toProcess) {
          HashSet<String> componentIdsToProcess = new HashSet<String>();
          for (String componentId : toProcess) {
            UIComponent component = getUtils().findComponentFor(uiComponent, componentId);
            if (null != component) {
              componentIdsToProcess.add(component.getClientId(facesContext));
            } else {
              componentIdsToProcess.add(componentId);
            }
          }
          AjaxContext.getCurrentInstance(facesContext).setAjaxAreasToProcess(componentIdsToProcess);
        }
      }
    }
  }
  @Override
  public void decode(FacesContext facesContext, UIComponent uiComponent) {

    InputFile inputFile = (InputFile) uiComponent;

    Map<String, List<UploadedFile>> uploadedFileMap =
        getUploadedFileMap(facesContext, inputFile.getLocation());

    if (uploadedFileMap != null) {

      String clientId = uiComponent.getClientId(facesContext);
      List<UploadedFile> uploadedFiles = uploadedFileMap.get(clientId);

      if ((uploadedFiles != null) && (uploadedFiles.size() > 0)) {

        inputFile.setSubmittedValue(uploadedFiles);

        // Queue the FileUploadEvent so that each uploaded file can be handled individually with an
        // ActionListener.
        for (UploadedFile uploadedFile : uploadedFiles) {

          FileUploadEvent fileUploadEvent = new FileUploadEvent(uiComponent, uploadedFile);
          uiComponent.queueEvent(fileUploadEvent);
        }
      }
    }
  }
Esempio n. 3
0
  @Override
  public void decode(FacesContext context, UIComponent component, ClientBehavior behavior) {
    if (null == context || null == component || null == behavior) {
      throw new NullPointerException();
    }

    if (!(behavior instanceof AjaxBehavior)) {
      // TODO: use MessageUtils for this error message?
      throw new IllegalArgumentException(
          "Instance of javax.faces.component.behavior.AjaxBehavior required: " + behavior);
    }

    AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;

    // First things first - if AjaxBehavior is disabled, we are done.
    if (ajaxBehavior.isDisabled()) {
      return;
    }

    component.queueEvent(createEvent(context, component, ajaxBehavior));

    if (logger.isLoggable(Level.FINE)) {
      logger.fine("This command resulted in form submission " + " AjaxBehaviorEvent queued.");
      logger.log(Level.FINE, "End decoding component {0}", component.getId());
    }
  }
 public void decode(FacesContext context, UIComponent component) {
   if (context
       .getExternalContext()
       .getRequestParameterMap()
       .containsKey(component.getClientId(context))) {
     component.queueEvent(new ActionEvent(component));
   }
 }
  @Override
  public void decode(FacesContext context, UIComponent component) {
    CommandLink link = (CommandLink) component;
    if (link.isDisabled()) {
      return;
    }

    String param = component.getClientId();

    if (context.getExternalContext().getRequestParameterMap().containsKey(param)) {
      component.queueEvent(new ActionEvent(component));
    }
  }
  /**
   * This method overrides the {@link #decode(FacesContext, UIComponent)} method so that it can
   * avoid a Servlet-API dependency in the RichFaces FileUploadRenderer. Note that rich:fileUpload
   * will do an Ajax postback and invoke the JSF lifecycle for each individual file.
   */
  @Override
  public void decode(FacesContext facesContext, UIComponent uiComponent) {

    try {

      // Get the UploadedFile from the request attribute map.
      ContextMapFactory contextMapFactory =
          (ContextMapFactory) FactoryExtensionFinder.getFactory(ContextMapFactory.class);
      BridgeContext bridgeContext = BridgeContext.getCurrentInstance();
      Map<String, Collection<UploadedFile>> uploadedFileMap =
          contextMapFactory.getUploadedFileMap(bridgeContext);

      if (uploadedFileMap != null) {

        // Use reflection to create a dynamic proxy class that implements the RichFaces UploadedFile
        // interface.
        Class<?> uploadedFileInterface = Class.forName(RICHFACES_UPLOADED_FILE_FQCN);
        Class<?> fileUploadEventClass = Class.forName(RICHFACES_FILE_UPLOAD_EVENT_FQCN);
        ClassLoader classLoader = uploadedFileInterface.getClassLoader();

        String clientId = uiComponent.getClientId(facesContext);
        Collection<UploadedFile> uploadedFiles = uploadedFileMap.get(clientId);

        if (uploadedFiles != null) {

          for (UploadedFile uploadedFile : uploadedFiles) {
            RichFacesUploadedFileHandler richFacesUploadedFileHandler =
                new RichFacesUploadedFileHandler(uploadedFile);
            Object richFacesUploadedFile =
                Proxy.newProxyInstance(
                    classLoader, new Class[] {uploadedFileInterface}, richFacesUploadedFileHandler);
            FacesEvent fileUploadEvent =
                (FacesEvent)
                    fileUploadEventClass
                        .getConstructor(UIComponent.class, uploadedFileInterface)
                        .newInstance(uiComponent, richFacesUploadedFile);

            // Queue the RichFaces FileUploadEvent instance so that it can be handled with an
            // ActionListener.
            uiComponent.queueEvent(fileUploadEvent);
          }
        }
      }
    } catch (Exception e) {
      logger.error(e);
    }
  }