0

我正在尝试获取值表达式中包含的值。我需要使用它进行一些验证。当我在 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");
4

1 回答 1

0

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

请参阅setRowIndex(int)文档:

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