【问题标题】:Get Values from a valueExpression JSF1.2从 valueExpression JSF1.2 中获取值
【发布时间】:2023-03-11 23:18:02
【问题描述】:

我正在尝试获取值表达式中包含的值。我需要使用它进行一些验证。当我在 HTMLOutput 中设置值表达式时,它会显示在屏幕上。请建议我做错了什么?

HtmlOutputText output = new HtmlOutputText();
ve = ef.createValueExpression(elCtx, "#{dynamicRow["+ i + "]}", String.class);
//I have tried all options here that I came across.
//Either test1 , test2 , test3 should have the value ve has, but all of them have value "".
String test1 = (String)ve.getValue(elCtx);
String test2 = (String)output.getValue();
Application app = fCtx.getApplication( );
String test3 = (String) app.evaluateExpressionGet(fCtx, "#{dynamicRow["+ i + "]}", String.class);
output.setValueExpression("value", ve);
//the ve gets displayed in the column with correct string values and not ""
column.getChildren().add(output);
// I also tried ValueReference as given in ValueExpression: how to get base Object?
ValueReference valueReference = ve.getValueReference(elCtx);
//an exception is thrown here javax.el.PropertyNotFoundException: Target Unreachable, identifier 'dynamicRow' resolved to null
Object base = valueReference.getBase();
Object property = valueReference.getProperty();

我的表有以下代码:

FacesContext fCtx = FacesContext.getCurrentInstance();
ELContext elCtx = fCtx.getELContext();
ExpressionFactory ef = fCtx.getApplication().getExpressionFactory();
HtmlExtendedDataTable dynamicDataTable = new HtmlExtendedDataTable();
HtmlDatascroller datascroller = new HtmlDatascroller();
ValueExpression ve = ef.createValueExpression(elCtx,"#{myController.dynamicList}", List.class);
dynamicDataTable.setValueExpression("value", ve);
dynamicDataTable.setVar("dynamicRow");

【问题讨论】:

    标签: jsf el


    【解决方案1】:

    vardynamicRow 仅在处理期间 table 将其置于范围内时才在范围内。这是通过组件上的各种process* 方法完成的。

    参见setRowIndex(int) 文档:

    • 保存所有后代组件的当前状态信息(如下所述)。
    • 存储新的行索引,并将其传递给与此 UIData 实例关联的 DataModel。
    • 如果新的 rowIndex 值为 -1:
      • 如果var 属性不为空,请移除相应的请求范围属性(如果有)。
      • 重置所有后代组件的状态信息(如下所述)。
    • 如果新的 rowIndex 值不是 -1:
      • 如果var 属性不为空,则调用 getRowData() 并将生成的数据对象公开为请求范围属性,其键为 var 属性值。
      • 重置所有后代组件的状态信息(如下所述)。

    【讨论】:

    • 你能推荐一些例子吗?我是 JSF 的新手,还没有做太多。
    • 我不明白你为什么有这些代码。为什么不直接在模型上查找数据?
    猜你喜欢
    • 2012-09-04
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多