Esempio n. 1
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;
 }
Esempio n. 2
0
  protected Converter createConverter() throws JspException {
    FacesContext context = FacesContext.getCurrentInstance();
    ELContext elctx = context.getELContext();

    if (binding != null) {
      Converter boundConverter = (NumberConverter) binding.getValue(elctx);
      if (boundConverter != null) return boundConverter;
    }

    NumberConverter converter = new NumberConverter();

    if (currencyCode != null) converter.setCurrencyCode((String) currencyCode.getValue(elctx));
    if (currencySymbol != null)
      converter.setCurrencySymbol((String) currencySymbol.getValue(elctx));
    if (groupingUsed != null) converter.setGroupingUsed((Boolean) groupingUsed.getValue(elctx));
    if (integerOnly != null) converter.setIntegerOnly((Boolean) integerOnly.getValue(elctx));
    if (maxFractionDigits != null)
      converter.setMaxFractionDigits((Integer) maxFractionDigits.getValue(elctx));
    if (minFractionDigits != null)
      converter.setMinFractionDigits((Integer) minFractionDigits.getValue(elctx));
    if (minIntegerDigits != null)
      converter.setMinIntegerDigits((Integer) minIntegerDigits.getValue(elctx));
    if (pattern != null) converter.setPattern((String) pattern.getValue(elctx));
    if (type != null) converter.setType((String) type.getValue(elctx));

    Locale loc = null;
    if (locale != null) loc = FacesUtils.getLocaleFromExpression(context, locale);
    if (loc == null) loc = context.getViewRoot().getLocale();
    converter.setLocale(loc);

    if (binding != null) binding.setValue(elctx, converter);
    return converter;
  }
Esempio n. 3
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()));
  }
Esempio n. 4
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()));
  }
  /**
   * 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;
  }
Esempio n. 8
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;
  }
 static final String evalString(ValueExpression expr, FacesContext context) {
   try {
     return (String) expr.getValue(context.getELContext());
   } catch (ELException e) {
     throw new FacesException(e);
   }
 }
Esempio n. 10
0
 static final int evalInt(ValueExpression expr, FacesContext context) {
   try {
     return (Integer) expr.getValue(context.getELContext());
   } catch (ELException e) {
     throw new FacesException(e);
   }
 }
Esempio n. 11
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);
   }
 }
Esempio n. 12
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);
    }
  }
Esempio n. 13
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));
   }
 }
Esempio n. 14
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;
  }
  @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;
  }
Esempio n. 16
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());
    }
  }
Esempio n. 17
0
  /** 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;
  }
    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
  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);
    }
  }
Esempio n. 20
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 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);
    }
  }
Esempio n. 22
0
 public static Object evaluateValueExpression(ValueExpression expression, ELContext elContext) {
   if (expression.isLiteralText()) {
     return expression.getExpressionString();
   } else {
     return expression.getValue(elContext);
   }
 }
Esempio n. 23
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 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);
 }
Esempio n. 25
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());
 }
Esempio n. 26
0
  public void testLegacyVariableResolversWithUnifiedEL() {

    ValueExpression ve1 =
        application
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{customVRTest1}", Object.class);
    Object result = ve1.getValue(getFacesContext().getELContext());
    assertTrue(result.equals("TestVariableResolver"));

    ValueExpression ve2 =
        application
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{customVRTest2}", Object.class);
    result = ve2.getValue(getFacesContext().getELContext());
    assertTrue(result.equals("TestOldVariableResolver"));
  }
  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);
    }
  }
Esempio n. 28
0
  public void testLegacyPropertyResolversWithUnifiedEL() {

    ValueExpression ve1 =
        application
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{mixedBean.customPRTest1}", Object.class);
    Object result = ve1.getValue(getFacesContext().getELContext());
    assertTrue(result.equals("TestPropertyResolver"));

    ValueExpression ve2 =
        application
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{mixedBean.customPRTest2}", Object.class);
    result = ve2.getValue(getFacesContext().getELContext());
    assertTrue(result.equals("PropertyResolverTestImpl"));
  }
 @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));
 }
Esempio n. 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);
   }
 }