Esempio n. 1
0
 public void updateModel(FacesContext context, UIComponent comp) {
   // System.out.println(getDesc(comp, "UPDATE"));
   // System.out.println("  valid: " + isComponentValid(comp));
   // System.out.println("  setLocalValueInValueBinding: " + setLocalValueInValueBinding);
   if (!isComponentValid(comp) || !setLocalValueInValueBinding) {
     return;
   }
   // System.out.println("  value: " + value);
   ValueBinding vb = comp.getValueBinding(name);
   // System.out.println("  vb: " + vb);
   if (vb == null) return;
   try {
     vb.setValue(context, value);
     // System.out.println("  vb.setValue worked");
     clearValue();
   } catch (PropertyNotFoundException e) {
     // System.out.println("PropertyNotFoundException: " + e);
     // It's ok for the application to not use a settable ValueBinding,
     //  since the UIComponent can keep the value. But they probably
     //  don't mean to, so we should log something
     log.info(e);
     // Don't keep trying to set it
     discontinueSettingLocalValueInValueBinding();
   } catch (Exception e) {
     // System.out.println("Exception: " + e);
     String msgId = comp.getClass().getName() + '.' + name;
     Object label = MessageUtils.getComponentLabel(context, comp);
     FacesMessage msg = MessageUtils.getMessage(context, msgId, new Object[] {label, value});
     if (msg != null) context.addMessage(comp.getClientId(context), msg);
     setInvalid(comp);
   }
 }
 @Override
 public void setParent(UIComponent parent) {
   if (parent != null && !(parent instanceof DataTable))
     throw new FacesException(
         getClass().getName()
             + " component can only be placed in a DataTable component, but it was placed into a component with class: "
             + parent.getClass().getName()
             + "; if you need to add selection support to a TreeTable use SingleNodeSelection or MultipleNodeSelection component instead.");
   super.setParent(parent);
 }
  /**
   * Write pass thru attributes associated with the UIComponent parameter.
   *
   * @param writer
   * @param uiComponent
   * @throws IOException
   */
  public static void renderHtmlAttributes(
      ResponseWriter writer, UIComponent uiComponent, String[] htmlAttributes) throws IOException {
    if (writer == null) {
      throw new FacesException("Null pointer exception");
    }

    if (uiComponent == null) {
      throw new FacesException("Component instance is null");
    }

    // For now, we just support accelerating h: component rendering
    boolean stockAttribTracking = ImplementationUtil.isStockAttributeTracking();
    boolean attribTracking =
        stockAttribTracking
            && uiComponent.getClass().getName().startsWith("javax.faces.component.");
    List attributesThatAreSet =
        (!attribTracking)
            ? null
            : (List)
                uiComponent
                    .getAttributes()
                    .get("javax.faces.component.UIComponentBase.attributesThatAreSet");

    if (!attribTracking || (attributesThatAreSet != null && attributesThatAreSet.size() > 0)) {

      String nextPassThruAttributeName = null;
      Object nextPassThruAttributeValue = null;

      for (int i = 0; i < htmlAttributes.length; i++) {
        nextPassThruAttributeName = htmlAttributes[i];
        if (attribTracking
            && (attributesThatAreSet == null
                || !attributesThatAreSet.contains(nextPassThruAttributeName))) {
          continue;
        }
        nextPassThruAttributeValue = uiComponent.getAttributes().get(nextPassThruAttributeName);
        // Only render non-null attributes.
        // Some components have integer attribute values
        // set to the Wrapper classes' minimum value - don't render
        // an attribute with this sentinel value.
        if (nextPassThruAttributeValue != null
            && !valueIsIntegerSentinelValue(nextPassThruAttributeValue)) {
          writer.writeAttribute(
              nextPassThruAttributeName,
              nextPassThruAttributeValue,
              nextPassThruAttributeValue.toString());
        }
      }
    }
    // this call maintains the css related changes made by the effects on the client
    // especially the "visible" attribute.
    CurrentStyle.apply(FacesContext.getCurrentInstance(), uiComponent, writer);
  }
 private Method getMethod(UIComponent component) {
   Method result = null;
   try {
     if (component != null) {
       result = getExpectedBeanGetter(component.getClass());
     } else {
       _logger.warning("Attempting to access a method of a null component");
     }
   } catch (Exception e) {
     _logger.log(Level.WARNING, "Unhandled Exception", e);
   }
   return result;
 }
Esempio n. 5
0
 private String getDesc(UIComponent comp, String meth) {
   StringBuffer sb = new StringBuffer(256);
   if (comp != null) {
     String className = comp.getClass().getName();
     int index = className.lastIndexOf('.');
     if (index >= 0) className = className.substring(index + 1);
     sb.append(className);
     sb.append('.');
   }
   sb.append(meth);
   sb.append("  name: ");
   sb.append(name);
   if (comp != null) {
     sb.append("  clientId: ");
     sb.append(comp.getClientId(FacesContext.getCurrentInstance()));
   }
   return sb.toString();
 }
  protected UIComponent findCoreFormRecurse(UIComponent uiComponent) {
    UIComponent coreForm = null;

    if (uiComponent.getClass().toString().endsWith("CoreForm")) {
      coreForm = uiComponent;
    } else {
      List<UIComponent> children = uiComponent.getChildren();

      for (UIComponent child : children) {
        coreForm = findCoreFormRecurse(child);

        if (coreForm != null) {
          break;
        }
      }
    }

    return coreForm;
  }
Esempio n. 7
0
  protected void doNewComponentActions(FaceletContext ctx, String id, UIComponent c) {

    if (log.isLoggable(Level.FINE)) {
      log.fine(owner.getTag() + " Component[" + id + "] Created: " + c.getClass().getName());
    }
    // If this is NOT a composite component...
    if (null == createCompositeComponentDelegate) {
      // set the attributes and properties into the UIComponent instance.
      owner.setAttributes(ctx, c);
    }
    // otherwise, allow the composite component code to do it.

    // mark it owned by a facelet instance
    c.getAttributes().put(ComponentSupport.MARK_CREATED, id);

    if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)) {
      // inject the location into the component
      c.getAttributes().put(UIComponent.VIEW_LOCATION_KEY, owner.getTag().getLocation());
    }
  }
 /**
  * After nornal setting <code>parent</code> property in case of created component set Ajax
  * properties for parent.
  *
  * @see javax.faces.component.UIComponentBase#setParent(javax.faces.component.UIComponent)
  */
 public void setParent(UIComponent parent) {
   super.setParent(parent);
   if (null != parent && parent.getFamily() != null) {
     if (log.isDebugEnabled()) {
       log.debug(Messages.getMessage(Messages.CALLED_SET_PARENT, parent.getClass().getName()));
     }
     // TODO If this comopnent configured, set properties for parent
     // component.
     // NEW created component have parent, restored view - null in My
     // faces.
     // and SUN RI not call at restore saved view.
     // In other case - set in restoreState method.
     // if (parent.getParent() != null)
     {
       if (log.isDebugEnabled()) {
         log.debug(Messages.getMessage(Messages.DETECT_NEW_COMPONENT));
       }
       setParentProperties(parent);
     }
   }
 }
  public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
    // http://javaserverfaces.java.net/nonav/docs/2.0/pdldocs/facelets/index.html
    // Finally make sure the component is only rendered in the header of the
    // HTML document.
    UIComponent component = event.getComponent();
    FacesContext context = FacesContext.getCurrentInstance();
    if (log.isLoggable(Level.FINER)) {
      log.finer("processEvent for component = " + component.getClass().getName());
    }
    context.getViewRoot().addComponentResource(context, component, HTML.HEAD_ELEM);

    ClientDescriptor client =
        ClientDescriptor.getInstance(
            (HttpServletRequest) context.getExternalContext().getRequest());
    String themeParam = context.getExternalContext().getRequestParameterMap().get("theme");
    Theme theme = null;
    if (client.isIE9orLessBrowser()) {
      theme = Theme.ARCHAIC;
    } else {
      theme =
          Theme.getEnum(
              themeParam != null
                  ? themeParam
                  : (String) event.getComponent().getAttributes().get("theme"));
      if (theme == null) {
        String targetView = (String) event.getComponent().getAttributes().get("view");
        theme = CSSUtils.deriveTheme(targetView, JSFUtils.getRequest());
      }
    }

    // android and honeycomb themes deprecated
    if (theme == Theme.ANDROID || theme == Theme.HONEYCOMB) {
      theme = Theme.ANDROID_DARK;
    }
    context.getExternalContext().getSessionMap().put(MOBI_THEME_KEY, theme);
  }
  public static void addFacetOrAttributeAsOption(
      String name, Map<String, Object> options, FacesContext facesContext, UIComponent component) {

    UIComponent facet = component.getFacet(name);
    if (facet != null && facet.isRendered()) {
      ResponseWriter originalResponseWriter = facesContext.getResponseWriter();
      try {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintWriter printWriter = new PrintWriter(outputStream);
        ResponseWriter newResponseWriter =
            facesContext.getRenderKit().createResponseWriter(printWriter, null, null);
        facesContext.setResponseWriter(newResponseWriter);
        facet.encodeAll(facesContext);
        printWriter.flush();
        String value = new String(outputStream.toByteArray());
        options.put(name, value);
      } catch (IOException e) {
        throw new FacesException(
            "Can't encode facet '"
                + name
                + "' of component '"
                + component.getClass().getName()
                + "'",
            e);
      } finally {
        facesContext.setResponseWriter(originalResponseWriter);
      }
      return;
    }

    Object attribute = component.getAttributes().get(name);
    if (attribute != null) {
      options.put(name, attribute.toString());
      return;
    }
  }
Esempio n. 11
0
  /**
   * @param component the UIComponent in question
   * @return <code>true</code> if the component is within the <code>javax.faces.component</code> or
   *     <code>javax.faces.component.html</code> packages, otherwise return <code>false</code>
   */
  private static boolean canBeOptimized(UIComponent component) {

    Package p = component.getClass().getPackage();
    return ((p != null) && (Arrays.binarySearch(OPTIMIZED_PACKAGES, p.getName()) >= 0));
  }
Esempio n. 12
0
  @Override
  protected void encodeAll(
      FacesContext context, RenderingContext arc, UIComponent component, FacesBean bean)
      throws IOException {
    // Since Train is a naming container, we can be more
    // efficient about skipping its children
    if (!PartialPageUtils.containsPprTargets(arc, component, getClientId(context, component))) {
      return;
    }

    if (!(component instanceof UIXProcess)) {
      throw new ClassCastException(
          _LOG.getMessage(
              "TRAINRENDERER_ONLY_RENDERS_INSTANCE",
              new Object[] {UIXProcess.class.getName(), component.getClass().getName()}));
    }

    if (arc.getFormData() == null) {
      _LOG.warning("TRAIN_MUST_INSIDE_FORM");
      return;
    }

    UIXProcess process = (UIXProcess) component;
    UIComponent stamp = process.getNodeStamp();

    if (stamp != null) {
      Train train = new Train(context, arc, process, stamp);
      try {
        process.setRowKey(train.getFocusRowKey());

        // Renders some fields and scripts
        _renderHiddenFields(context, arc, train);

        ResponseWriter writer = context.getResponseWriter();

        // Need to render the frame even if there's no visible station
        // to support PPR.
        writer.startElement(XhtmlConstants.TABLE_ELEMENT, component);
        process.setRowKey(train.getInitialRowKey());
        renderId(context, component);
        renderAllAttributes(context, arc, bean);
        // Does not seem to be needed and this is not XHTML 1.0 Strict compliant
        // writer.writeAttribute("align", "center", null);

        if (!train.getStations().isEmpty()) {
          process.setRowKey(train.getFocusRowKey());

          // There're visible stations currently, let render them.
          writer.startElement(XhtmlConstants.TABLE_BODY_ELEMENT, null);
          _renderTrain(context, arc, process, bean, stamp, train);
          writer.endElement(XhtmlConstants.TABLE_BODY_ELEMENT);
        }

        writer.endElement(XhtmlConstants.TABLE_ELEMENT);
      } finally {
        // Always restore the model, whatever happened
        process.setRowKey(train.getInitialRowKey());
      }
    } else {
      _LOG.warning("NODESTAMP_FACET_NOT_FOUND_FOR_TRAIN", component);
    }
    /*
      _encodeChildren(context, arc, process, stamp, trainState, length);
    */
  }
Esempio n. 13
0
  private void printComponentTree(
      PrintWriter out, String errorId, FacesContext context, UIComponent comp, int depth) {
    for (int i = 0; i < depth; i++) out.print(' ');

    boolean isError = false;
    if (errorId != null && errorId.equals(comp.getClientId(context))) {
      isError = true;
      out.print("<span style='color:red'>");
    }

    out.print("&lt;" + comp.getClass().getSimpleName());
    if (comp.getId() != null) out.print(" id=\"" + comp.getId() + "\"");

    for (Method method : comp.getClass().getMethods()) {
      if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue;
      else if (method.getParameterTypes().length != 0) continue;

      String name;

      if (method.getName().startsWith("get")) name = method.getName().substring(3);
      else if (method.getName().startsWith("is")) name = method.getName().substring(2);
      else continue;

      // XXX: getURL
      name = Character.toLowerCase(name.charAt(0)) + name.substring(1);

      ValueExpression expr = comp.getValueExpression(name);

      Class type = method.getReturnType();

      if (expr != null) {
        out.print(" " + name + "=\"" + expr.getExpressionString() + "\"");
      } else if (method.getDeclaringClass().equals(UIComponent.class)
          || method.getDeclaringClass().equals(UIComponentBase.class)) {
      } else if (name.equals("family")) {
      } else if (String.class.equals(type)) {
        try {
          Object value = method.invoke(comp);

          if (value != null) out.print(" " + name + "=\"" + value + "\"");
        } catch (Exception e) {
        }
      }
    }

    int facetCount = comp.getFacetCount();
    int childCount = comp.getChildCount();

    if (facetCount == 0 && childCount == 0) {
      out.print("/>");

      if (isError) out.print("</span>");

      out.println();
      return;
    }
    out.println(">");

    if (isError) out.print("</span>");

    for (int i = 0; i < childCount; i++) {
      printComponentTree(out, errorId, context, comp.getChildren().get(i), depth + 1);
    }

    for (int i = 0; i < depth; i++) out.print(' ');

    if (isError) out.print("<span style='color:red'>");

    out.println("&lt;/" + comp.getClass().getSimpleName() + ">");

    if (isError) out.print("</span>");
  }