@Override
  protected void doDecode(FacesContext context, UIComponent component) {
    super.doDecode(context, component);

    UITab tab = (UITab) component;
    UITabPanel panel = tab.getPane();

    Map<String, String> requestParameterMap = context.getExternalContext().getRequestParameterMap();

    if (AjaxRendererUtils.isAjaxRequest(context)
        && tab.getSwitchTypeOrDefault().equals(UISwitchablePanel.AJAX_METHOD)
        && requestParameterMap.get(tab.getClientId(context)) != null) {

      // add toggle panel itself to rendered list of components
      AjaxRendererUtils.addRegionByName(context, panel, panel.getId());
      AjaxRendererUtils.addRegionsFromComponent(tab, context);

      AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
      Set<String> toProcess = ajaxContext.getAjaxAreasToProcess();
      if (toProcess == null) {
        toProcess = new HashSet<String>(1);
        ajaxContext.setAjaxAreasToProcess(toProcess);
      }
      toProcess.add(panel.getClientId(context));

      ajaxContext.addAreasToProcessFromComponent(context, tab);
    }
  }
  /* (non-Javadoc)
   * @see javax.faces.render.Renderer#encodeChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
   */
  public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
    //
    UIAjaxOutputPanel panel = (UIAjaxOutputPanel) component;
    if ("none".equals(panel.getLayout())) {
      if (component.getChildCount() > 0) {
        AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
        boolean ajaxRequest = ajaxContext.isAjaxRequest();
        Set<String> ajaxRenderedAreas = ajaxContext.getAjaxRenderedAreas();
        for (UIComponent child : component.getChildren()) {
          String childId = child.getClientId(context);
          if (child.isRendered()) {
            renderChild(context, child);
          } else {
            // Render "dummy" span.
            ResponseWriter out = context.getResponseWriter();
            out.startElement(HTML.SPAN_ELEM, child);
            out.writeAttribute(HTML.id_ATTRIBUTE, childId, HTML.id_ATTRIBUTE);
            out.writeAttribute(HTML.style_ATTRIBUTE, "display: none;", "style");
            out.endElement(HTML.SPAN_ELEM);
          }
          // register child as rendered
          if (ajaxRequest && null != ajaxRenderedAreas) {
            ajaxRenderedAreas.add(childId);
          }
        }
      }

    } else {
      renderChildren(context, component);
    }
  }
Esempio n. 3
0
 @SuppressWarnings("unchecked")
 private void put2ResponseData(String key, Object value) {
   AjaxContext ajaxContext = getAjaxContext();
   if (ajaxContext != null) {
     Map<String, Object> data = (Map<String, Object>) ajaxContext.getResponseData();
     if (null == data) {
       data = new HashMap<String, Object>();
       ajaxContext.setResponseData(data);
     }
     data.put(key, value);
   }
 }
  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);
        }
      }
    }
  }
 protected boolean isSubmitted(FacesContext facesContext, UIComponent uiComponent) {
   // Componet accept only ajax requests.
   if (!AjaxContext.getCurrentInstance(facesContext).isAjaxRequest()) {
     return false;
   }
   if (getUtils().isBooleanAttribute(uiComponent, "disabled")) {
     return false;
   }
   String clientId = uiComponent.getClientId(facesContext);
   Map<String, String> paramMap = facesContext.getExternalContext().getRequestParameterMap();
   Object value = paramMap.get(clientId);
   boolean submitted = null != value;
   if (submitted && _log.isDebugEnabled()) {
     _log.debug("Decode submit of the Ajax component " + clientId);
   }
   return submitted;
 }