示例#1
0
 @Override
 public Class getPropertyType(String name) {
   PropertyDescriptor compDescriptor = findDescriptor(name);
   if (compDescriptor != null) {
     // composite:attribute declaration...
     ValueExpression typeVE = (ValueExpression) compDescriptor.getValue("type");
     if (typeVE == null) {
       return Object.class;
     } else {
       String className =
           (String) typeVE.getValue(FacesContext.getCurrentInstance().getELContext());
       if (className != null) {
         className = prefix(className);
         try {
           return ReflectionUtil.forName(className);
         } catch (ClassNotFoundException cnfe) {
           throw new FacesException(cnfe);
         }
       } else {
         return Object.class;
       }
     }
   } else {
     // defer to the default processing which will inspect the
     // PropertyDescriptor of the UIComponent type
     return super.getPropertyType(name);
   }
 }
示例#2
0
 public void applyAttachedObject(FacesContext context, UIComponent parent) {
   FaceletContext ctx =
       (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
   // cast to a ValueHolder
   ValueHolder vh = (ValueHolder) parent;
   ValueExpression ve = null;
   Converter c = null;
   if (this.binding != null) {
     ve = this.binding.getValueExpression(ctx, Converter.class);
     c = (Converter) ve.getValue(ctx);
   }
   if (c == null) {
     c = this.createConverter(ctx);
     if (ve != null) {
       ve.setValue(ctx, c);
     }
   }
   if (c == null) {
     throw new TagException(this.tag, "No Converter was created");
   }
   this.setAttributes(ctx, c);
   vh.setConverter(c);
   Object lv = vh.getLocalValue();
   FacesContext faces = ctx.getFacesContext();
   if (lv instanceof String) {
     vh.setValue(c.getAsObject(faces, parent, (String) lv));
   }
 }
示例#3
0
  private final MethodExpression getMethodExpression(EvaluationContext ctx) throws ELException {
    Object obj = null;

    // case A: ValueExpression exists, getValue which must
    // be a MethodExpression
    VariableMapper varMapper = ctx.getVariableMapper();
    ValueExpression ve = null;
    if (varMapper != null) {
      ve = varMapper.resolveVariable(this.image);
      if (ve != null) {
        obj = ve.getValue(ctx);
      }
    }

    // case B: evaluate the identity against the ELResolver, again, must be
    // a MethodExpression to be able to invoke
    if (ve == null) {
      ctx.setPropertyResolved(false);
      obj = ctx.getELResolver().getValue(ctx, null, this.image);
    }

    // finally provide helpful hints
    if (obj instanceof MethodExpression) {
      return (MethodExpression) obj;
    } else if (obj == null) {
      throw new MethodNotFoundException(
          "Identity '" + this.image + "' was null and was unable to invoke");
    } else {
      throw new ELException(
          "Identity '"
              + this.image
              + "' does not reference a MethodExpression instance, returned type: "
              + obj.getClass().getName());
    }
  }
  @Override
  protected void setProperties(UIComponent component) {
    if (component instanceof SiteTreeViewer) {
      if (rootNodeExpression == null) {
        new IllegalArgumentException("Provide root node");
      }

      Object o = null;
      IWContext iwc = CoreUtil.getIWContext();
      if (iwc == null) {
        return;
      }

      ValueExpression ve =
          WFUtil.createValueExpression(getELContext(), rootNodeExpression, TreeNode.class);
      o = ve.getValue(getELContext());
      if (!(o instanceof TreeNode)) {
        new IllegalArgumentException("Provide root node");
      }
      rootNode = (TreeNode) o;

      SiteTreeViewer treeViewer = (SiteTreeViewer) component;

      treeViewer.setRootNode(rootNode);
      treeViewer.setLinkStyleClass(linkStyleClass);
      treeViewer.setIwTreeId(iwTreeId);
      treeViewer.setRendererType(rendererType);
      treeViewer.setFacetName(facetName);
      treeViewer.setVarName(varName);
      treeViewer.setSourceTree(sourceTree);
      treeViewer.setShowRootNode(showRootNode);
      treeViewer.setShowLines(showLines);
      treeViewer.setAddStyleClassForLink(addStyleClassForLink);
    }
  }
示例#5
0
  public UIComponent createComponent(FaceletContext ctx) {

    FacesContext context = ctx.getFacesContext();
    UIComponent cc;
    // we have to handle the binding here, as Application doesn't
    // expose a method to do so with Resource.
    if (binding != null) {
      ValueExpression ve = binding.getValueExpression(ctx, UIComponent.class);
      cc = (UIComponent) ve.getValue(ctx);
      if (cc != null && !UIComponent.isCompositeComponent(cc)) {
        if (LOGGER.isLoggable(Level.SEVERE)) {
          LOGGER.log(Level.SEVERE, "jsf.compcomp.binding.eval.non.compcomp", binding.toString());
        }
        cc = null;
      }
      if (cc == null) {
        cc = context.getApplication().createComponent(context, ccResource);
        ve.setValue(ctx, cc);
      }
    } else {
      cc = context.getApplication().createComponent(context, ccResource);
    }
    setCompositeComponent(context, cc);

    return cc;
  }
示例#6
0
  // Sets a property, converting it from a literal
  private void setLiteralValue(String propertyName, ValueExpression expression) {

    assert (expression.isLiteralText());

    Object value;
    ELContext context = FacesContext.getCurrentInstance().getELContext();

    try {
      value = expression.getValue(context);
    } catch (ELException ele) {
      throw new FacesException(ele);
    }

    if (ONEVENT.equals(propertyName)) {
      onevent = (String) value;
    } else if (ONERROR.equals(propertyName)) {
      onerror = (String) value;
    } else if (IMMEDIATE.equals(propertyName)) {
      immediate = (Boolean) value;
    } else if (DISABLED.equals(propertyName)) {
      disabled = (Boolean) value;
    } else if (EXECUTE.equals(propertyName)) {
      execute = toList(propertyName, expression, value);
    } else if (RENDER.equals(propertyName)) {
      render = toList(propertyName, expression, value);
    }
  }
示例#7
0
 @Override
 public Object getValue(ELContext context) {
   ELContext nxcontext = getLocalContext(context);
   Object res = null;
   if (originalValueExpression != null) {
     res = originalValueExpression.getValue(nxcontext);
     if (res instanceof String) {
       String expression = (String) res;
       if (ComponentTagUtils.isValueReference(expression)) {
         FacesContext faces = FacesContext.getCurrentInstance();
         Application app = faces.getApplication();
         ExpressionFactory factory = app.getExpressionFactory();
         ValueExpression newExpr =
             factory.createValueExpression(nxcontext, expression, expectedType);
         try {
           res = newExpr.getValue(nxcontext);
         } catch (ELException err) {
           log.error("Error processing expression " + expression + ": " + err);
           res = null;
         }
       } else {
         res = expression;
       }
     }
   }
   return res;
 }
  /** If page >= 1 then it's a page number to show */
  @Attribute
  public int getPage() {

    UIComponent dataTable = getDataTable();
    Map<String, Object> attributes = dataTable.getAttributes();

    FacesContext facesContext = getFacesContext();
    Integer state =
        (Integer) attributes.get(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE);

    if (state != null) {
      return state;
    }

    if (this.page != null) {
      return page;
    }

    ValueExpression ve = getValueExpression("page");
    if (ve != null) {
      try {
        Integer pageObject = (Integer) ve.getValue(getFacesContext().getELContext());

        if (pageObject != null) {
          return pageObject;
        }
      } catch (ELException e) {
        throw new FacesException(e);
      }
    }

    return 1;
  }
示例#9
0
  @SuppressWarnings("unchecked")
  private Collection<String> getCollectionValue(
      String propertyName, Collection<String> collection) {
    if (collection != null) {
      return collection;
    }

    Collection<String> result = null;
    ValueExpression expression = getValueExpression(propertyName);

    if (expression != null) {

      FacesContext ctx = FacesContext.getCurrentInstance();
      Object value = expression.getValue(ctx.getELContext());

      if (value != null) {

        if (value instanceof Collection) {
          // Unchecked cast to Collection<String>
          return (Collection<String>) value;
        }

        result = toList(propertyName, expression, value);
      }
    }

    return result == null ? Collections.<String>emptyList() : result;
  }
    public void processEvent(FacesEvent event) throws AbortProcessingException {

      FacesContext faces = FacesContext.getCurrentInstance();
      if (faces == null) {
        return;
      }

      L instance = null;
      if (this.binding != null) {
        instance = (L) binding.getValue(faces.getELContext());
      }
      if (instance == null && this.type != null) {
        try {
          instance = (L) TagHandlerUtils.loadClass(this.type, Object.class).newInstance();
        } catch (Exception e) {
          throw new AbortProcessingException("Couldn't Lazily instantiate EventListener", e);
        }
        if (this.binding != null) {
          binding.setValue(faces.getELContext(), instance);
        }
      }

      if (instance != null) {
        event.processListener(instance);
      }
    }
  @Override
  public void apply(FaceletContext ctx, UIComponent component)
      throws IOException, FacesException, FaceletException, ELException {
    AutoCompleteSelectItemsBean bean = new AutoCompleteSelectItemsBean();

    if (unlessAttribute != null) {
      if (ObjectExtractor.extractBoolean(
          getValueExpression(unlessAttribute, ctx, Object.class), ctx)) {
        return;
      }
    }

    bean.setColumn(
        ObjectExtractor.extractString(getValueExpression(columnAttribute, ctx, String.class), ctx));
    bean.setJndi(
        ObjectExtractor.extractString(getValueExpression(jndiAttribute, ctx, String.class), ctx));
    bean.setLabel(
        ObjectExtractor.extractString(getValueExpression(labelAttribute, ctx, String.class), ctx));
    bean.setTable(
        ObjectExtractor.extractString(getValueExpression(tableAttribute, ctx, String.class), ctx));

    if (keyAttribute != null)
      bean.setKey(
          ObjectExtractor.extractString(getValueExpression(keyAttribute, ctx, String.class), ctx));

    if (likeAttribute != null)
      bean.setLike(
          ObjectExtractor.extractBoolean(
              getValueExpression(likeAttribute, ctx, Object.class), ctx));

    ValueExpression beanExpression =
        getValueExpression(beanAttribute, ctx, AutoCompleteSelectItemsBean.class);
    beanExpression.setValue(ctx, bean);
  }
  /**
   * Set a property of type int[]. If the value is an EL expression, it will be stored as a
   * ValueExpression. Otherwise, it will parsed as a whitespace-separated series of ints. Null
   * values are ignored.
   */
  protected void setIntArrayProperty(FacesBean bean, PropertyKey key, ValueExpression expression) {
    if (expression == null) return;

    if (expression.isLiteralText()) {
      Object value = expression.getValue(null);
      if (value != null) {
        String[] strings = _parseNameTokens(value);
        final int[] ints;
        if (strings != null) {
          try {
            ints = new int[strings.length];
            for (int i = 0; i < strings.length; i++) {
              int j = Integer.parseInt(strings[i]);
              ints[i] = j;
            }
          } catch (NumberFormatException e) {
            _LOG.severe("CANNOT_CONVERT_INTO_INT_ARRAY", value);
            _LOG.severe(e);
            return;
          }
        }
      }
    } else {
      bean.setValueExpression(key, expression);
    }
  }
  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;
  }
示例#15
0
  @Override
  public Object getAsObject(FacesContext context, UIComponent component, String value) {

    if (context == null) {
      throw new NullPointerException("context");
    }
    if (component == null) {
      throw new NullPointerException("component");
    }
    FacesContext ctx = FacesContext.getCurrentInstance();
    ValueExpression vex =
        ctx.getApplication()
            .getExpressionFactory()
            .createValueExpression(
                ctx.getELContext(), "#{managedBeanDepartamento}", ManagedBeanDepartamento.class);
    ManagedBeanDepartamento managedBean =
        (ManagedBeanDepartamento) vex.getValue(ctx.getELContext());
    Departamento objeto;
    try {
      objeto = managedBean.traerObjeto(value);

    } catch (NumberFormatException e) {
      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR, "Valor Desconocido", "NumberFormatException");
      throw new ConverterException(message);
    }
    if (objeto == null) {
      FacesMessage message =
          new FacesMessage(FacesMessage.SEVERITY_ERROR, "Valor Desconocido", "Object NULL");
      throw new ConverterException(message);
    }
    return objeto;
  }
示例#16
0
  public void updateModel(FacesContext facesContext) {
    if (facesContext == null) {
      throw new NullPointerException();
    }

    if (!isValid() || !isLocalValueSet()) {
      return;
    }

    ValueExpression ve = getValueExpression("value");
    if (ve == null) {
      return;
    }

    Throwable caught = null;
    FacesMessage message = null;
    try {
      ve.setValue(facesContext.getELContext(), getLocalValue());
      setValue(null);
      setLocalValueSet(false);
    } catch (ELException e) {
      caught = e;
      String messageStr = e.getMessage();
      Throwable result = e.getCause();
      while (null != result && result.getClass().isAssignableFrom(ELException.class)) {
        messageStr = result.getMessage();
        result = result.getCause();
      }

      if (messageStr == null) {
        message =
            ServiceTracker.getService(MessageFactory.class)
                .createMessage(
                    facesContext,
                    FacesMessage.SEVERITY_ERROR,
                    FacesMessages.UIINPUT_UPDATE,
                    MessageUtil.getLabel(facesContext, this));
      } else {
        message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr);
      }
      setValid(false);
    } catch (Exception e) {
      caught = e;
      // message = MessageFactory.getMessage(facesContext, UPDATE_MESSAGE_ID,
      // MessageFactory.getHeader(facesContext, this));
      setValid(false);
    }

    if (caught != null) {
      assert message != null;

      @SuppressWarnings({"ThrowableInstanceNeverThrown"})
      UpdateModelException toQueue = new UpdateModelException(message, caught);
      ExceptionQueuedEventContext eventContext =
          new ExceptionQueuedEventContext(facesContext, toQueue, this, PhaseId.UPDATE_MODEL_VALUES);
      facesContext
          .getApplication()
          .publishEvent(facesContext, ExceptionQueuedEvent.class, eventContext);
    }
  }
  public void apply(FaceletContext context, UIComponent parent)
      throws IOException, FacesException, ELException {
    if (parent == null || !(parent instanceof EditableValueHolder))
      throw new TagException(tag, "Parent not an instance of EditableValueHolder: " + parent);
    if (parent.getParent() == null) {
      EditableValueHolder editableValueHolder = (EditableValueHolder) parent;
      ValueExpression valueExpression = null;
      Validator validator = null;
      if (binding != null) {
        valueExpression =
            binding.getValueExpression(context, javax.faces.validator.Validator.class);
        validator = (Validator) valueExpression.getValue(context);
      }
      if (validator == null) {
        validator = createValidator(context);
        if (valueExpression != null) valueExpression.setValue(context, validator);
      }
      if (validator == null) throw new TagException(tag, "No Validator was created");

      if (nextHandler instanceof CompositeFaceletHandler) {
        addParameters(context, (CompositeFaceletHandler) nextHandler);
      } else if (nextHandler instanceof MessageParameterTagHandler) {
        addParameter(context, (MessageParameterTagHandler) nextHandler);
      }

      setAttributes(context, validator);
      editableValueHolder.addValidator(validator);
    }
  }
  @Override
  public Object getAsObject(FacesContext context, UIComponent component, String value) {

    if (context == null) {
      throw new NullPointerException("context");
    }
    if (component == null) {
      throw new NullPointerException("component");
    }
    FacesContext ctx = FacesContext.getCurrentInstance();
    ValueExpression vex =
        ctx.getApplication()
            .getExpressionFactory()
            .createValueExpression(
                ctx.getELContext(), "#{managedBeanUnidadMedida}", ManagedBeanUnidadMedida.class);
    ManagedBeanUnidadMedida unidades = (ManagedBeanUnidadMedida) vex.getValue(ctx.getELContext());
    UnidadMedida unidad;
    try {
      unidad = unidades.getUnidadMedida(new Integer(value));
    } catch (NumberFormatException e) {
      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR,
              "Valor Desconocido",
              "Este no es un Numero de Unidad de Medida");
      throw new ConverterException(message);
    }
    if (unidad == null) {
      FacesMessage message =
          new FacesMessage(
              FacesMessage.SEVERITY_ERROR, "Valor Desconocido", "La Unidad de Medida desconocida");
      throw new ConverterException(message);
    }
    return unidad;
  }
示例#19
0
  public static Converter getItemConverter(FacesContext facesContext, UIComponent component) {
    Converter converter = null;
    if (component instanceof ValueHolder) {
      // If the component has an attached Converter, use it.
      converter = ((ValueHolder) component).getConverter();
      if (converter != null) {
        return converter;
      }
    }
    // If not, look for a ValueExpression for value (if any). The ValueExpression must point to
    // something that is:
    ValueExpression ve = component.getValueExpression("value");
    if (ve != null) {
      Class<?> valueType = ve.getType(facesContext.getELContext());
      // An array of primitives (such as int[]). Look up the registered by-class Converter for this
      // primitive type.
      // An array of objects (such as Integer[] or String[]). Look up the registered by-class
      // Converter for the underlying element type.
      if (valueType != null && valueType.isArray()) {
        converter = facesContext.getApplication().createConverter(valueType);
      }
      // A java.util.Collection. Do not convert the values.
    }
    if (converter == null) {
      // Spec says "If for any reason a Converter cannot be found, assume the type to be a String
      // array." However
      // if we don't have an explicit converter, see if one is registered for the class of the
      // SelectItem values
      Iterator<SelectItem> selectItems = SelectUtils.getSelectItems(facesContext, component);
      converter = getSelectItemConverter(facesContext.getApplication(), selectItems);
    }

    return converter;
  }
示例#20
0
 /**
  * * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
  * javax.faces.component.UIComponent)
  */
 public void apply(FaceletContext ctx, UIComponent parent)
     throws IOException, FacesException, FaceletException, ELException {
   VariableMapper origVarMap = ctx.getVariableMapper();
   try {
     VariableMapperWrapper variableMap = new VariableMapperWrapper(origVarMap);
     ctx.setVariableMapper(variableMap);
     if (methodBindings != null) {
       String value = (String) methodBindings.getValue(ctx);
       Matcher match = METHOD_PATTERN.matcher(value);
       while (match.find()) {
         String var = match.group(1);
         ValueExpression currentExpression = origVarMap.resolveVariable(var);
         if (currentExpression != null) {
           try {
             FunctionMethodData methodData =
                 new FunctionMethodData(var, match.group(2).split("\\s+"));
             MethodExpression mexpr =
                 buildMethodExpression(ctx, currentExpression.getExpressionString(), methodData);
             variableMap.setVariable(var, new MethodValueExpression(currentExpression, mexpr));
           } catch (Exception ex) {
             throw new FacesException(ex);
           }
         }
       }
     }
     componentHandler.apply(ctx, parent);
   } finally {
     ctx.setVariableMapper(origVarMap);
   }
 }
示例#21
0
 public static Object evaluateValueExpression(ValueExpression expression, ELContext elContext) {
   if (expression.isLiteralText()) {
     return expression.getExpressionString();
   } else {
     return expression.getValue(elContext);
   }
 }
示例#22
0
 protected Object evaluate(String ref) throws Exception {
   ValueExpression ve =
       this.getFacesContext()
           .getApplication()
           .getExpressionFactory()
           .createValueExpression(getFacesContext().getELContext(), ref, Object.class);
   return ve.getValue(this.getFacesContext().getELContext());
 }
示例#23
0
  public void testMixedBeanPositive() throws Exception {
    ValueExpression vb = ELUtils.createValueExpression("#{threeBeanSaladPositive}");
    TestBean bean = (TestBean) vb.getValue(getFacesContext().getELContext());
    assertEquals("request request session session none none", bean.getProp());

    vb = ELUtils.createValueExpression("#{threeBeanSaladPositive.prop}");
    assertEquals(bean.getProp(), (String) vb.getValue(getFacesContext().getELContext()));
  }
示例#24
0
  public void testMixedBean() throws Exception {
    ValueExpression vb = ELUtils.createValueExpression("#{mixedBean}");
    TestBean bean = (TestBean) vb.getValue(getFacesContext().getELContext());
    assertEquals("mixed value Bobby \" \\  \\\" Orr", bean.getProp());

    vb = ELUtils.createValueExpression("#{mixedBean.prop}");
    assertEquals(bean.getProp(), (String) vb.getValue(getFacesContext().getELContext()));
  }
 @Test
 public void testBug50790b() throws Exception {
   ValueExpression ve =
       factory.createValueExpression(
           context, "#{beanA.name.contains(beanAA.name)}", java.lang.Boolean.class);
   Boolean actual = (Boolean) ve.getValue(context);
   assertEquals(Boolean.FALSE, actual);
 }
示例#26
0
  public double getMaxX() {
    if (_maxX != null) return _maxX;

    ValueExpression ve = getValueExpression("maxX");
    return ve != null
        ? (java.lang.Double) ve.getValue(getFacesContext().getELContext())
        : java.lang.Double.MIN_VALUE;
  }
 @Test
 public void testBugPrimitives() throws Exception {
   MethodExpression me =
       factory.createMethodExpression(context, "${beanA.setValLong(5)}", null, null);
   me.invoke(context, null);
   ValueExpression ve =
       factory.createValueExpression(context, "#{beanA.valLong}", java.lang.String.class);
   assertEquals("5", ve.getValue(context));
 }
示例#28
0
  private void updateStateHelper(final String propertyName, final Object value) {
    this.getStateHelper().put(propertyName, value);

    final ValueExpression ve = this.getValueExpression(propertyName);

    if (ve != null) {
      ve.setValue(this.getFacesContext().getELContext(), value);
    }
  }
  protected void setProperty(FacesBean bean, PropertyKey key, ValueExpression expression) {
    if (expression == null) return;

    if (expression.isLiteralText()) {
      bean.setProperty(key, expression.getValue(null));
    } else {
      bean.setValueExpression(key, expression);
    }
  }
示例#30
0
 protected void beforeEncode() {
   ValueExpression expansionStateExpression = getValueExpression("expansionState");
   if (expansionStateExpression != null) {
     FacesContext context = getFacesContext();
     ExpansionState newExpansionState =
         (ExpansionState) expansionStateExpression.getValue(context.getELContext());
     if (newExpansionState != null) setExpansionState(newExpansionState);
   }
 }