本文整理汇总了Java中javax.el.ValueExpression.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java ValueExpression.getValue方法的具体用法?Java ValueExpression.getValue怎么用?Java ValueExpression.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.el.ValueExpression
的用法示例。
在下文中一共展示了ValueExpression.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug51544Direct
import javax.el.ValueExpression; //导入方法依赖的package包/类
/**
* Test using list directly as variable.
*/
@Test
public void testBug51544Direct() throws Exception {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
List<?> list = Collections.emptyList();
ValueExpression var =
factory.createValueExpression(list, List.class);
context.getVariableMapper().setVariable("list", var);
ValueExpression ve = factory.createValueExpression(
context, "${list.size()}", Integer.class);
Integer result = (Integer) ve.getValue(context);
assertEquals(Integer.valueOf(0), result);
}
示例2: getValue
import javax.el.ValueExpression; //导入方法依赖的package包/类
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
VariableMapper varMapper = ctx.getVariableMapper();
if (varMapper != null) {
ValueExpression expr = varMapper.resolveVariable(this.image);
if (expr != null) {
return expr.getValue(ctx.getELContext());
}
}
ctx.setPropertyResolved(false);
Object result = ctx.getELResolver().getValue(ctx, null, this.image);
if (!ctx.isPropertyResolved()) {
throw new PropertyNotFoundException(MessageFactory.get(
"error.resolver.unhandled.null", this.image));
}
return result;
}
示例3: doTestBug56179
import javax.el.ValueExpression; //导入方法依赖的package包/类
private void doTestBug56179(int parenthesesCount, String innerExpr) {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
ValueExpression var =
factory.createValueExpression(Boolean.TRUE, Boolean.class);
context.getVariableMapper().setVariable("test", var);
StringBuilder expr = new StringBuilder();
expr.append("${");
for (int i = 0; i < parenthesesCount; i++) {
expr.append("(");
}
expr.append(innerExpr);
for (int i = 0; i < parenthesesCount; i++) {
expr.append(")");
}
expr.append("}");
ValueExpression ve = factory.createValueExpression(
context, expr.toString(), String.class);
String result = (String) ve.getValue(context);
assertEquals("true", result);
}
示例4: testBug53792b
import javax.el.ValueExpression; //导入方法依赖的package包/类
@Test
public void testBug53792b() {
MethodExpression me = factory.createMethodExpression(context,
"${beanA.setBean(beanB)}", null ,
new Class<?>[] { TesterBeanB.class });
me.invoke(context, null);
me = factory.createMethodExpression(context,
"${beanB.setName('" + BUG53792 + "')}", null ,
new Class<?>[] { TesterBeanB.class });
me.invoke(context, null);
ValueExpression ve = factory.createValueExpression(context,
"#{beanA.getBean().name.length()}", java.lang.Integer.class);
Integer actual = (Integer) ve.getValue(context);
assertEquals(Integer.valueOf(BUG53792.length()), actual);
}
示例5: testBug51544Bean
import javax.el.ValueExpression; //导入方法依赖的package包/类
/**
* Test returning an empty list as a bean property.
*/
@Test
public void testBug51544Bean() throws Exception {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
TesterBeanA beanA = new TesterBeanA();
beanA.setValList(Collections.emptyList());
ValueExpression var =
factory.createValueExpression(beanA, TesterBeanA.class);
context.getVariableMapper().setVariable("beanA", var);
ValueExpression ve = factory.createValueExpression(
context, "${beanA.valList.size()}", Integer.class);
Integer result = (Integer) ve.getValue(context);
assertEquals(Integer.valueOf(0), result);
}
示例6: getValue
import javax.el.ValueExpression; //导入方法依赖的package包/类
@Override
public Object getValue(EvaluationContext ctx) throws ELException {
VariableMapper varMapper = ctx.getVariableMapper();
if (varMapper != null) {
ValueExpression expr = varMapper.resolveVariable(this.image);
if (expr != null) {
return expr.getValue(ctx.getELContext());
}
}
ctx.setPropertyResolved(false);
Object result = ctx.getELResolver().getValue(ctx, null, this.image);
if (!ctx.isPropertyResolved()) {
throw new PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled.null", this.image));
}
return result;
}
示例7: getMethodExpression
import javax.el.ValueExpression; //导入方法依赖的package包/类
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());
}
}
示例8: safeEL
import javax.el.ValueExpression; //导入方法依赖的package包/类
public void safeEL() {
FacesContext context = FacesContext.getCurrentInstance();
ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
ELContext elContext = context.getELContext();
ValueExpression vex = expressionFactory.createValueExpression(elContext, "1+1", String.class);
String result = (String) vex.getValue(elContext);
System.out.println(result);
}
示例9: testBug50790a
import javax.el.ValueExpression; //导入方法依赖的package包/类
@Test
public void testBug50790a() throws Exception {
ValueExpression ve = factory.createValueExpression(context,
"#{beanAA.name.contains(beanA.name)}", java.lang.Boolean.class);
Boolean actual = (Boolean) ve.getValue(context);
assertEquals(Boolean.TRUE, actual);
}
示例10: testBug50790b
import javax.el.ValueExpression; //导入方法依赖的package包/类
@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);
}
示例11: evalAttr
import javax.el.ValueExpression; //导入方法依赖的package包/类
private String evalAttr(String expression, char quote) {
ELContextImpl ctx = new ELContextImpl();
ctx.setFunctionMapper(new FMapper());
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
ValueExpression ve = exprFactory.createValueExpression(ctx,
AttributeParser.getUnquoted(expression, quote, false, false,
false, false),
String.class);
return (String) ve.getValue(ctx);
}
示例12: unsafeEL
import javax.el.ValueExpression; //导入方法依赖的package包/类
public void unsafeEL(String expression) {
FacesContext context = FacesContext.getCurrentInstance();
ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
ELContext elContext = context.getELContext();
ValueExpression vex = expressionFactory.createValueExpression(elContext, expression, String.class);
String result = (String) vex.getValue(elContext);
System.out.println(result);
}
示例13: testBug49345
import javax.el.ValueExpression; //导入方法依赖的package包/类
@Test
public void testBug49345() {
ExpressionFactory factory = ExpressionFactory.newInstance();
ELContext context = new ELContextImpl();
TesterBeanA beanA = new TesterBeanA();
TesterBeanB beanB = new TesterBeanB();
beanB.setName("Tomcat");
beanA.setBean(beanB);
ValueExpression var =
factory.createValueExpression(beanA, TesterBeanA.class);
context.getVariableMapper().setVariable("beanA", var);
ValueExpression ve = factory.createValueExpression(
context, "${beanA.bean.name}", String.class);
// First check the basics work
String result = (String) ve.getValue(context);
assertEquals("Tomcat", result);
// Now check the value reference
ValueReference vr = ve.getValueReference(context);
assertNotNull(vr);
assertEquals(beanB, vr.getBase());
assertEquals("name", vr.getProperty());
}
示例14: evaluateExpression
import javax.el.ValueExpression; //导入方法依赖的package包/类
private String evaluateExpression(String expression) {
ELContextImpl ctx = new ELContextImpl();
ctx.setFunctionMapper(new FMapper());
ExpressionFactoryImpl exprFactory = new ExpressionFactoryImpl();
ValueExpression ve = exprFactory.createValueExpression(ctx, expression,
String.class);
return (String) ve.getValue(ctx);
}
示例15: setIntArrayProperty
import javax.el.ValueExpression; //导入方法依赖的package包/类
/**
* 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(FacesContext.getCurrentInstance().getELContext());
if (value != null)
{
String[] strings = TagUtils.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);
}
}