Ejemplo n.º 1
0
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    javax.faces.component.UIOutput output = null;
    try {
      output = (javax.faces.component.UIOutput) component;
    } catch (ClassCastException cce) {
      throw new IllegalStateException(
          "Component "
              + component.toString()
              + " not expected type.  Expected: javax.faces.component.UIOutput.  Perhaps you're missing a tag?");
    }

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

    if (value != null) {
      if (!value.isLiteralText()) {
        output.setValueExpression("value", value);
      } else {
        output.setValue(value.getExpressionString());
      }
    }
    if (escape != null) {
      if (!escape.isLiteralText()) {
        output.setValueExpression("escape", escape);
      } else {
        output
            .getAttributes()
            .put("escape", java.lang.Boolean.valueOf(escape.getExpressionString()));
      }
    }
    if (style != null) {
      if (!style.isLiteralText()) {
        output.setValueExpression("style", style);
      } else {
        output.getAttributes().put("style", style.getExpressionString());
      }
    }
    if (styleClass != null) {
      if (!styleClass.isLiteralText()) {
        output.setValueExpression("styleClass", styleClass);
      } else {
        output.getAttributes().put("styleClass", styleClass.getExpressionString());
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Algorithm works as follows; - If it's an input component, submitted value is checked first
   * since it'd be the value to be used in case validation errors terminates jsf lifecycle - Finally
   * the value of the component is retrieved from backing bean and if there's a converter, converted
   * value is returned
   *
   * <p>- If the component is not a value holder, toString of component is used to support Facelets
   * UIInstructions.
   *
   * @param facesContext FacesContext instance
   * @param component UIComponent instance whose value will be returned
   * @return End text
   */
  public static String getStringValueToRender(FacesContext facesContext, UIComponent component) {
    if (component instanceof ValueHolder) {

      if (component instanceof EditableValueHolder) {
        Object submittedValue = ((EditableValueHolder) component).getSubmittedValue();
        if (submittedValue != null) {
          return submittedValue.toString();
        }
      }

      ValueHolder valueHolder = (ValueHolder) component;
      Object value = valueHolder.getValue();
      if (value == null) return "";

      // first ask the converter
      if (valueHolder.getConverter() != null) {
        return valueHolder.getConverter().getAsString(facesContext, component, value);
      }
      // Try to guess
      else {
        ValueExpression expr = component.getValueExpression("value");
        if (expr != null) {
          Class<?> valueType = expr.getType(facesContext.getELContext());
          if (valueType != null) {
            Converter converterForType = facesContext.getApplication().createConverter(valueType);

            if (converterForType != null)
              return converterForType.getAsString(facesContext, component, value);
          }
        }
      }

      // No converter found just return the value as string
      return value.toString();
    } else {
      // This would get the plain texts on UIInstructions when using Facelets
      String value = component.toString();

      if (value != null) return value.trim();
      else return "";
    }
  }
Ejemplo n.º 3
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.º 4
0
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    javax.faces.component.UICommand command = null;
    try {
      command = (javax.faces.component.UICommand) component;
    } catch (ClassCastException cce) {
      throw new IllegalStateException(
          "Component "
              + component.toString()
              + " not expected type.  Expected: javax.faces.component.UICommand.  Perhaps you're missing a tag?");
    }

    if (action != null) {
      command.setActionExpression(action);
    }
    if (actionListener != null) {
      command.addActionListener(new MethodExpressionActionListener(actionListener));
    }
    if (immediate != null) {
      if (!immediate.isLiteralText()) {
        command.setValueExpression("immediate", immediate);
      } else {
        command.setImmediate(
            java.lang.Boolean.valueOf(immediate.getExpressionString()).booleanValue());
      }
    }
    if (label != null) {
      if (!label.isLiteralText()) {
        command.setValueExpression("label", label);
      } else {
        command.getAttributes().put("label", label.getExpressionString());
      }
    }
    if (oncommand != null) {
      if (!oncommand.isLiteralText()) {
        command.setValueExpression("oncommand", oncommand);
      } else {
        command.getAttributes().put("oncommand", oncommand.getExpressionString());
      }
    }
    if (onclick != null) {
      if (!onclick.isLiteralText()) {
        command.setValueExpression("onclick", onclick);
      } else {
        command.getAttributes().put("onclick", onclick.getExpressionString());
      }
    }
    if (onfocusin != null) {
      if (!onfocusin.isLiteralText()) {
        command.setValueExpression("onfocusin", onfocusin);
      } else {
        command.getAttributes().put("onfocusin", onfocusin.getExpressionString());
      }
    }
    if (onfocusout != null) {
      if (!onfocusout.isLiteralText()) {
        command.setValueExpression("onfocusout", onfocusout);
      } else {
        command.getAttributes().put("onfocusout", onfocusout.getExpressionString());
      }
    }
    if (onmousedown != null) {
      if (!onmousedown.isLiteralText()) {
        command.setValueExpression("onmousedown", onmousedown);
      } else {
        command.getAttributes().put("onmousedown", onmousedown.getExpressionString());
      }
    }
    if (onmousemove != null) {
      if (!onmousemove.isLiteralText()) {
        command.setValueExpression("onmousemove", onmousemove);
      } else {
        command.getAttributes().put("onmousemove", onmousemove.getExpressionString());
      }
    }
    if (onmouseout != null) {
      if (!onmouseout.isLiteralText()) {
        command.setValueExpression("onmouseout", onmouseout);
      } else {
        command.getAttributes().put("onmouseout", onmouseout.getExpressionString());
      }
    }
    if (onmouseover != null) {
      if (!onmouseover.isLiteralText()) {
        command.setValueExpression("onmouseover", onmouseover);
      } else {
        command.getAttributes().put("onmouseover", onmouseover.getExpressionString());
      }
    }
    if (onmouseup != null) {
      if (!onmouseup.isLiteralText()) {
        command.setValueExpression("onmouseup", onmouseup);
      } else {
        command.getAttributes().put("onmouseup", onmouseup.getExpressionString());
      }
    }
    if (style != null) {
      if (!style.isLiteralText()) {
        command.setValueExpression("style", style);
      } else {
        command.getAttributes().put("style", style.getExpressionString());
      }
    }
    if (styleClass != null) {
      if (!styleClass.isLiteralText()) {
        command.setValueExpression("styleClass", styleClass);
      } else {
        command.getAttributes().put("styleClass", styleClass.getExpressionString());
      }
    }
    if (type != null) {
      if (!type.isLiteralText()) {
        command.setValueExpression("type", type);
      } else {
        command.getAttributes().put("type", type.getExpressionString());
      }
    }
    if (value != null) {
      if (!value.isLiteralText()) {
        command.setValueExpression("value", value);
      } else {
        command.setValue(value.getExpressionString());
      }
    }
  }
Ejemplo n.º 5
0
  protected void setProperties(UIComponent component) {
    super.setProperties(component);
    javax.faces.component.UIPanel panel = null;
    try {
      panel = (javax.faces.component.UIPanel) component;
    } catch (ClassCastException cce) {
      throw new IllegalStateException(
          "Component "
              + component.toString()
              + " not expected type.  Expected: javax.faces.component.UIPanel.  Perhaps you're missing a tag?");
    }

    if (bgcolor != null) {
      if (!bgcolor.isLiteralText()) {
        panel.setValueExpression("bgcolor", bgcolor);
      } else {
        panel.getAttributes().put("bgcolor", bgcolor.getExpressionString());
      }
    }
    if (border != null) {
      if (!border.isLiteralText()) {
        panel.setValueExpression("border", border);
      } else {
        panel
            .getAttributes()
            .put("border", java.lang.Integer.valueOf(border.getExpressionString()));
      }
    }
    if (columnClasses != null) {
      if (!columnClasses.isLiteralText()) {
        panel.setValueExpression("columnClasses", columnClasses);
      } else {
        panel.getAttributes().put("columnClasses", columnClasses.getExpressionString());
      }
    }
    if (columns != null) {
      if (!columns.isLiteralText()) {
        panel.setValueExpression("columns", columns);
      } else {
        panel
            .getAttributes()
            .put("columns", java.lang.Integer.valueOf(columns.getExpressionString()));
      }
    }
    if (onclick != null) {
      if (!onclick.isLiteralText()) {
        panel.setValueExpression("onclick", onclick);
      } else {
        panel.getAttributes().put("onclick", onclick.getExpressionString());
      }
    }
    if (ondblclick != null) {
      if (!ondblclick.isLiteralText()) {
        panel.setValueExpression("ondblclick", ondblclick);
      } else {
        panel.getAttributes().put("ondblclick", ondblclick.getExpressionString());
      }
    }
    if (onkeydown != null) {
      if (!onkeydown.isLiteralText()) {
        panel.setValueExpression("onkeydown", onkeydown);
      } else {
        panel.getAttributes().put("onkeydown", onkeydown.getExpressionString());
      }
    }
    if (onkeypress != null) {
      if (!onkeypress.isLiteralText()) {
        panel.setValueExpression("onkeypress", onkeypress);
      } else {
        panel.getAttributes().put("onkeypress", onkeypress.getExpressionString());
      }
    }
    if (onkeyup != null) {
      if (!onkeyup.isLiteralText()) {
        panel.setValueExpression("onkeyup", onkeyup);
      } else {
        panel.getAttributes().put("onkeyup", onkeyup.getExpressionString());
      }
    }
    if (onmousedown != null) {
      if (!onmousedown.isLiteralText()) {
        panel.setValueExpression("onmousedown", onmousedown);
      } else {
        panel.getAttributes().put("onmousedown", onmousedown.getExpressionString());
      }
    }
    if (onmousemove != null) {
      if (!onmousemove.isLiteralText()) {
        panel.setValueExpression("onmousemove", onmousemove);
      } else {
        panel.getAttributes().put("onmousemove", onmousemove.getExpressionString());
      }
    }
    if (onmouseout != null) {
      if (!onmouseout.isLiteralText()) {
        panel.setValueExpression("onmouseout", onmouseout);
      } else {
        panel.getAttributes().put("onmouseout", onmouseout.getExpressionString());
      }
    }
    if (onmouseover != null) {
      if (!onmouseover.isLiteralText()) {
        panel.setValueExpression("onmouseover", onmouseover);
      } else {
        panel.getAttributes().put("onmouseover", onmouseover.getExpressionString());
      }
    }
    if (onmouseup != null) {
      if (!onmouseup.isLiteralText()) {
        panel.setValueExpression("onmouseup", onmouseup);
      } else {
        panel.getAttributes().put("onmouseup", onmouseup.getExpressionString());
      }
    }
    if (rowClasses != null) {
      if (!rowClasses.isLiteralText()) {
        panel.setValueExpression("rowClasses", rowClasses);
      } else {
        panel.getAttributes().put("rowClasses", rowClasses.getExpressionString());
      }
    }
    if (style != null) {
      if (!style.isLiteralText()) {
        panel.setValueExpression("style", style);
      } else {
        panel.getAttributes().put("style", style.getExpressionString());
      }
    }
    if (styleClass != null) {
      if (!styleClass.isLiteralText()) {
        panel.setValueExpression("styleClass", styleClass);
      } else {
        panel.getAttributes().put("styleClass", styleClass.getExpressionString());
      }
    }
  }
Ejemplo n.º 6
0
  private void setOptions(UIComponent parent) {
    // create layout options for this pane via attributes defined in pe:layoutPane
    String position = getPosition();
    LayoutOptions thisLayoutOptions = getOptions();
    LayoutOptions options;

    if (parent instanceof LayoutPane) {
      LayoutOptions parentLayoutOptions = ((LayoutPane) parent).getOptions();
      options = parentLayoutOptions.getChildOptions();
      if (options == null) {
        options = new LayoutOptions();
        parentLayoutOptions.setChildOptions(options);
      }
    } else if (parent instanceof Layout) {
      options = (LayoutOptions) ((Layout) parent).getOptions();
      if (options == null) {
        Layout layout = ((Layout) parent);
        options = new LayoutOptions();
        layout.setOptions(options);

        // options for all panes
        LayoutOptions panes = null;
        String resizerTip = layout.getResizerTip();
        if (resizerTip != null) {
          panes = new LayoutOptions();
          panes.addOption(Layout.PropertyKeys.resizerTip.toString(), resizerTip);
        }

        String togglerTipOpen = layout.getTogglerTipOpen();
        if (togglerTipOpen != null) {
          if (panes == null) {
            panes = new LayoutOptions();
          }

          panes.addOption(Layout.PropertyKeys.togglerTip_open.toString(), togglerTipOpen);
        }

        String togglerTipClosed = layout.getTogglerTipClosed();
        if (togglerTipClosed != null) {
          if (panes == null) {
            panes = new LayoutOptions();
          }

          panes.addOption(Layout.PropertyKeys.togglerTip_closed.toString(), togglerTipClosed);
        }

        if (panes != null) {
          options.setPanesOptions(panes);
        }
      }
    } else if (parent instanceof UIForm) {
      // layout pane can be within a h:form
      setOptions(parent.getParent());

      return;
    } else if (parent instanceof HtmlPanelGroup
        && Layout.STYLE_CLASS_LAYOUT_CONTENT.equals(((HtmlPanelGroup) parent).getStyleClass())
        && "block".equals(((HtmlPanelGroup) parent).getLayout())) {
      // layout pane can be within h:panelGroup representing a HTML div
      setOptions(parent.getParent());

      return;
    } else if (parent instanceof OutputPanel
        && Layout.STYLE_CLASS_LAYOUT_CONTENT.equals(((OutputPanel) parent).getStyleClass())
        && "block".equals(((OutputPanel) parent).getLayout())) {
      // layout pane can be within p:outputPanel representing a HTML div
      setOptions(parent.getParent());

      return;
    } else if (parent != null && parent.toString().contains(Layout.STYLE_CLASS_LAYOUT_CONTENT)) {
      // plain div (UIInstructions) with class "ui-layout-content"
      setOptions(parent.getParent());

      return;
    } else {
      throw new FacesException(
          "LayoutPane can be only placed within another LayoutPane, Layout, UIForm or DIV with class 'ui-layout-content'");
    }

    if (Layout.PANE_POSITION_CENTER.equals(position)) {
      options.setCenterOptions(thisLayoutOptions);
    } else if (Layout.PANE_POSITION_NORTH.equals(position)) {
      options.setNorthOptions(thisLayoutOptions);
    } else if (Layout.PANE_POSITION_SOUTH.equals(position)) {
      options.setSouthOptions(thisLayoutOptions);
    } else if (Layout.PANE_POSITION_WEST.equals(position)) {
      options.setWestOptions(thisLayoutOptions);
    } else if (Layout.PANE_POSITION_EAST.equals(position)) {
      options.setEastOptions(thisLayoutOptions);
    } else {
      throw new FacesException(
          "Pane position "
              + position
              + " is invalid. Valid positions are 'center', 'north' 'south', 'west', 'east'");
    }
  }