public static UIComponent addTransient(
      FacesContext context, ServletRequest req, UIComponent parent, String prevId, Class childClass)
      throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();

      BodyContent body = parentTag.getBodyContent();

      if (body != null) addVerbatim(parent, body);
    }

    UIComponent child = null;
    ;

    if (child == null) child = (UIComponent) childClass.newInstance();

    child.setTransient(true);

    addChild(parent, prevId, child);

    return child;
  }
  public static UIComponent findPersistent(
      FacesContext context, ServletRequest req, UIComponent parent, String id) throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    BodyContent body = null;

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();

      body = parentTag.getBodyContent();
    }

    if (parent != null) {
      List<UIComponent> children = parent.getChildren();
      int size = children.size();

      String prevId = null;
      for (int i = 0; i < size; i++) {
        UIComponent child = children.get(i);

        if (id.equals(child.getId())) {
          if (body != null) addVerbatim(parent, prevId, body);

          return child;
        }

        if (child.getId() != null) prevId = child.getId();
      }
    }

    return null;
  }
Ejemplo n.º 3
0
  protected void setProperties(UIComponent component) {
    if (_binding != null) component.setValueExpression("binding", _binding);

    if (_rendered != null) component.setValueExpression("rendered", _rendered);

    String type = getRendererType();
    if (type != null) component.setRendererType(type);
  }
Ejemplo n.º 4
0
  private void doSetBindings(ELContext elContext, UIComponent component) {
    if (component == null) return;

    ValueExpression binding = component.getValueExpression("binding");

    if (binding != null) binding.setValue(elContext, component);

    Iterator<UIComponent> iter = component.getFacetsAndChildren();
    while (iter.hasNext()) doSetBindings(elContext, iter.next());
  }
  public static UIComponent addFacet(
      FacesContext context,
      ServletRequest req,
      UIComponent parent,
      String facetName,
      ValueExpression binding,
      Class childClass)
      throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();
    }

    UIComponent child = null;

    if (binding != null) child = (UIComponent) binding.getValue(context.getELContext());

    if (child == null) child = (UIComponent) childClass.newInstance();

    if (parent != null) parent.getFacets().put(facetName, child);

    if (binding != null) binding.setValue(context.getELContext(), child);

    return child;
  }
  public static UIComponent addPersistent(
      FacesContext context,
      ServletRequest req,
      UIComponent parent,
      ValueExpression binding,
      Class childClass)
      throws Exception {
    if (context == null) context = FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();

      BodyContent body = parentTag.getBodyContent();

      addVerbatim(parent, body);
    }

    UIComponent child = null;

    if (binding != null) child = (UIComponent) binding.getValue(context.getELContext());

    if (child == null) {
      child = (UIComponent) childClass.newInstance();

      // jsf/3251
      if (binding != null) binding.setValue(context.getELContext(), child);
    }

    if (parent != null) parent.getChildren().add(child);

    return child;
  }
Ejemplo n.º 7
0
  @Override
  protected UIComponent createComponent(FacesContext context, String newId) throws JspException {
    Application app = context.getApplication();

    UIComponent component;

    if (_binding != null) {
      component = app.createComponent(_binding, context, getComponentType());
      component.setValueExpression("binding", _binding);
    } else component = app.createComponent(getComponentType());

    component.setId(getId());

    setProperties(component);

    return component;
  }
  private static void addChild(UIComponent parent, String prevId, UIComponent child) {
    if (parent != null) {
      List<UIComponent> children = parent.getChildren();
      int size = children.size();
      boolean hasPrev = prevId == null;

      int i = 0;
      for (; i < size; i++) {
        UIComponent oldChild = children.get(i);

        if (hasPrev && oldChild.getId() != null) {
          children.add(i, child);

          return;
        } else if (prevId != null && prevId.equals(oldChild.getId())) hasPrev = true;
      }

      parent.getChildren().add(child);
    }
  }
  public static UIComponent addVerbatim(UIComponent parent, String text) throws Exception {
    HtmlOutputText verbatim = new HtmlOutputText();

    verbatim.setTransient(true);
    verbatim.setValue(text);
    verbatim.setEscape(false);

    parent.getChildren().add(verbatim);

    return verbatim;
  }
  public static UIComponent findFacet(
      FacesContext context, ServletRequest req, UIComponent parent, String facetName)
      throws Exception {
    if (context == null) FacesContext.getCurrentInstance();

    if (parent == null) {
      UIComponentClassicTagBase parentTag =
          (UIComponentClassicTagBase) req.getAttribute("caucho.jsf.parent");

      parent = parentTag.getComponentInstance();
    }

    if (parent != null) return parent.getFacet(facetName);
    else return null;
  }
Ejemplo n.º 11
0
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    javax.faces.component.UISelectOne selectone = null;
    try {
      selectone = (javax.faces.component.UISelectOne) component;
    } catch (ClassCastException cce) {
      throw new IllegalStateException(
          "Component "
              + component.toString()
              + " not expected type.  Expected: javax.faces.component.UISelectOne.  Perhaps you're missing a tag?");
    }

    if (converter != null) {
      if (!converter.isLiteralText()) {
        selectone.setValueExpression("converter", converter);
      } else {
        Converter conv =
            FacesContext.getCurrentInstance()
                .getApplication()
                .createConverter(converter.getExpressionString());
        selectone.setConverter(conv);
      }
    }

    if (converterMessage != null) {
      selectone.setValueExpression("converterMessage", converterMessage);
    }

    if (immediate != null) {
      selectone.setValueExpression("immediate", immediate);
    }

    if (required != null) {
      selectone.setValueExpression("required", required);
    }

    if (requiredMessage != null) {
      selectone.setValueExpression("requiredMessage", requiredMessage);
    }

    if (validator != null) {
      selectone.addValidator(new MethodExpressionValidator(validator));
    }
    if (validatorMessage != null) {
      selectone.setValueExpression("validatorMessage", validatorMessage);
    }

    if (value != null) {
      selectone.setValueExpression("value", value);
    }

    if (valueChangeListener != null) {
      selectone.addValueChangeListener(
          new MethodExpressionValueChangeListener(valueChangeListener));
    }
    if (accesskey != null) {
      selectone.setValueExpression("accesskey", accesskey);
    }
    if (dir != null) {
      selectone.setValueExpression("dir", dir);
    }
    if (disabled != null) {
      selectone.setValueExpression("disabled", disabled);
    }
    if (disabledClass != null) {
      selectone.setValueExpression("disabledClass", disabledClass);
    }
    if (enabledClass != null) {
      selectone.setValueExpression("enabledClass", enabledClass);
    }
    if (label != null) {
      selectone.setValueExpression("label", label);
    }
    if (lang != null) {
      selectone.setValueExpression("lang", lang);
    }
    if (onblur != null) {
      selectone.setValueExpression("onblur", onblur);
    }
    if (onchange != null) {
      selectone.setValueExpression("onchange", onchange);
    }
    if (onclick != null) {
      selectone.setValueExpression("onclick", onclick);
    }
    if (ondblclick != null) {
      selectone.setValueExpression("ondblclick", ondblclick);
    }
    if (onfocus != null) {
      selectone.setValueExpression("onfocus", onfocus);
    }
    if (onkeydown != null) {
      selectone.setValueExpression("onkeydown", onkeydown);
    }
    if (onkeypress != null) {
      selectone.setValueExpression("onkeypress", onkeypress);
    }
    if (onkeyup != null) {
      selectone.setValueExpression("onkeyup", onkeyup);
    }
    if (onmousedown != null) {
      selectone.setValueExpression("onmousedown", onmousedown);
    }
    if (onmousemove != null) {
      selectone.setValueExpression("onmousemove", onmousemove);
    }
    if (onmouseout != null) {
      selectone.setValueExpression("onmouseout", onmouseout);
    }
    if (onmouseover != null) {
      selectone.setValueExpression("onmouseover", onmouseover);
    }
    if (onmouseup != null) {
      selectone.setValueExpression("onmouseup", onmouseup);
    }
    if (onselect != null) {
      selectone.setValueExpression("onselect", onselect);
    }
    if (readonly != null) {
      selectone.setValueExpression("readonly", readonly);
    }
    if (style != null) {
      selectone.setValueExpression("style", style);
    }
    if (styleClass != null) {
      selectone.setValueExpression("styleClass", styleClass);
    }
    if (tabindex != null) {
      selectone.setValueExpression("tabindex", tabindex);
    }
    if (title != null) {
      selectone.setValueExpression("title", title);
    }
  }
Ejemplo n.º 12
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>");
  }
Ejemplo n.º 13
0
  public static String getLabel(FacesContext context, UIComponent component) {
    String label = (String) component.getAttributes().get("label");

    if (label != null && !"".equals(label)) return label;
    else return component.getClientId(context);
  }