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);
    }
  }
 @Override
 public Class getType(FacesContext context) throws EvaluationException, PropertyNotFoundException {
   ELContext ctx = context.getELContext();
   try {
     return this.delegate.getType(ctx);
   } catch (javax.el.PropertyNotFoundException e) {
     throw new PropertyNotFoundException(e.getMessage(), e.getCause());
   } catch (ELException e) {
     throw new EvaluationException(e.getMessage(), e.getCause());
   }
 }
 @Override
 public void setValue(FacesContext context, Object value)
     throws EvaluationException, PropertyNotFoundException {
   ELContext ctx = context.getELContext();
   try {
     this.delegate.setValue(ctx, value);
   } catch (PropertyNotWritableException | javax.el.PropertyNotFoundException e) {
     throw new PropertyNotFoundException(e.getMessage(), e.getCause());
   } catch (ELException e) {
     throw new EvaluationException(e.getMessage(), e.getCause());
   }
 }
 public Expression parseExpression(String expression, Class expectedType, FunctionMapper fMapper)
     throws ELException {
   try {
     ELContextImpl ctx = new ELContextImpl(ELResolverImpl.DefaultResolver);
     if (fMapper != null) {
       ctx.setFunctionMapper(new FunctionMapperImpl(fMapper));
     }
     ValueExpression ve = this.factory.createValueExpression(ctx, expression, expectedType);
     return new ExpressionImpl(ve);
   } catch (javax.el.ELException e) {
     throw new ELParseException(e.getMessage());
   }
 }
 /**
  * Evaluates an expression within the scope of this processor's context.
  *
  * @param expression The String expression
  * @param type Expected result type
  * @param defaultValue Default value to return in case of error
  */
 public <T> T evaluate(String expression, Class<T> type, T defaultValue) {
   try {
     ValueExpression expr = expressions.parse(expression, type);
     Object result = expr.getValue(elContext);
     return type.cast(result);
   } catch (ELException e) {
     logger.log(
         Level.WARNING,
         "EL failure for gadget {0}: {1}",
         new Object[] {getTemplateContext().getGadget().getContext().getUrl(), e.getMessage()});
     return defaultValue;
   }
 }
Beispiel #6
0
  /**
   * @throws NullPointerException {@inheritDoc}
   * @throws ValidatorException {@inheritDoc}
   */
  public void validate(FacesContext context, UIComponent component, Object value)
      throws ValidatorException {

    if ((context == null) || (component == null)) {
      throw new NullPointerException();
    }
    if (value != null) {
      try {
        ELContext elContext = context.getELContext();
        methodExpression.invoke(elContext, new Object[] {context, component, value});
      } catch (ELException ee) {
        Throwable e = ee.getCause();
        if (e instanceof ValidatorException) {
          throw (ValidatorException) e;
        }
        String errInfo = ee.getMessage();
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, errInfo, errInfo);
        throw new ValidatorException(message, ee.getCause());
      }
    }
  }
  /**
   * <span class="changed_modified_2_0 changed_modified_2_2">Call</span> through to the {@link
   * MethodExpression} passed in our constructor. <span class="changed_added_2_0">First, try to
   * invoke the <code>MethodExpression</code> passed to the constructor of this instance, passing
   * the argument {@link ActionEvent} as the argument. If a {@link MethodNotFoundException} is
   * thrown, call to the zero argument <code>MethodExpression</code> derived from the <code>
   * MethodExpression</code> passed to the constructor of this instance. <span
   * class="changed_deleted_2_2">If that fails for any reason, throw an {@link
   * AbortProcessingException}, including the cause of the failure.</span></span>
   *
   * @throws NullPointerException {@inheritDoc}
   * @throws AbortProcessingException {@inheritDoc}
   */
  @Override
  public void processAction(ActionEvent actionEvent) throws AbortProcessingException {

    if (actionEvent == null) {
      throw new NullPointerException();
    }

    FacesContext context = FacesContext.getCurrentInstance();
    ELContext elContext = context.getELContext();

    try {
      try {
        methodExpressionOneArg.invoke(elContext, new Object[] {actionEvent});
      } catch (MethodNotFoundException mnfe) {
        methodExpressionZeroArg.invoke(elContext, new Object[] {});
      }
    } catch (ELException ee) {
      if (ee.getCause() instanceof AbortProcessingException) {
        throw (AbortProcessingException) ee.getCause();
      } else {
        throw (ELException) ee;
      }
    }
  }
  private void updateModel(int newPage) {

    FacesContext facesContext = getFacesContext();
    UIComponent dataTable = getDataTable();

    if (isRendered(dataTable)) {
      dataTable.getAttributes().put("first", (newPage - 1) * getRows(dataTable));
    }

    Map<String, Object> attributes = dataTable.getAttributes();
    attributes.put(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE, newPage);

    ValueExpression ve = getValueExpression("page");
    if (ve != null) {
      try {
        ve.setValue(facesContext.getELContext(), newPage);
        attributes.remove(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE);
      } catch (ELException e) {
        String messageStr = e.getMessage();
        Throwable result = e.getCause();
        while (null != result && result.getClass().isAssignableFrom(ELException.class)) {
          messageStr = result.getMessage();
          result = result.getCause();
        }
        FacesMessage message;
        if (null == messageStr) {
          message =
              ServiceTracker.getService(MessageFactory.class)
                  .createMessage(
                      facesContext,
                      FacesMessages.UIINPUT_UPDATE,
                      MessageUtil.getLabel(facesContext, this));
        } else {
          message = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageStr, messageStr);
        }
        facesContext.getExternalContext().log(message.getSummary(), result);
        facesContext.addMessage(getClientId(facesContext), message);
        facesContext.renderResponse();
      } catch (IllegalArgumentException e) {
        FacesMessage message =
            ServiceTracker.getService(MessageFactory.class)
                .createMessage(
                    facesContext,
                    FacesMessages.UIINPUT_UPDATE,
                    MessageUtil.getLabel(facesContext, this));
        facesContext.getExternalContext().log(message.getSummary(), e);
        facesContext.addMessage(getClientId(facesContext), message);
        facesContext.renderResponse();
      } catch (Exception e) {
        FacesMessage message =
            ServiceTracker.getService(MessageFactory.class)
                .createMessage(
                    facesContext,
                    FacesMessages.UIINPUT_UPDATE,
                    MessageUtil.getLabel(facesContext, this));
        facesContext.getExternalContext().log(message.getSummary(), e);
        facesContext.addMessage(getClientId(facesContext), message);
        facesContext.renderResponse();
      }
    }
  }
  /**
   * Evaluate the expression as a boolean.
   *
   * @param env the variable environment
   */
  @Override
  public boolean evalBoolean(ELContext env) throws ELException {
    Object aObj = _left.getValue(env);
    Object bObj = _right.getValue(env);

    if (aObj == bObj) return true;

    if (aObj == null || bObj == null) return false;

    Class aType = aObj.getClass();
    Class bType = bObj.getClass();

    if (aType == Boolean.class || bType == Boolean.class) {
      boolean a = toBoolean(aObj, env);
      boolean b = toBoolean(bObj, env);

      return a == b;
    }

    try {
      if (aObj instanceof BigDecimal || bObj instanceof BigDecimal) {
        BigDecimal a = toBigDecimal(aObj, env);
        BigDecimal b = toBigDecimal(bObj, env);

        return a.equals(b);
      }

      if (aType == Double.class
          || aType == Float.class
          || bType == Double.class
          || bType == Float.class) {
        double a = toDouble(aObj, env);
        double b = toDouble(bObj, env);

        return a == b;
      }

      if (aType == BigInteger.class || bType == BigInteger.class) {
        BigInteger a = toBigInteger(aObj, env);
        BigInteger b = toBigInteger(bObj, env);

        return a.equals(b);
      }

      if (aObj instanceof Number || bObj instanceof Number) {
        long a = toLong(aObj, env);
        long b = toLong(bObj, env);

        return a == b;
      }
    } catch (ELException e) {
      log.finest(L.l("`{0}' in `{1}'", e.getMessage(), this.toString()));

      return false;
    }

    // XXX: enum

    if (aObj instanceof String || bObj instanceof String) {
      String a = toString(aObj, env);
      String b = toString(bObj, env);

      return a.equals(b);
    }

    return aObj.equals(bObj);
  }