我正在尝试获取包含在值表达式中的值。我需要用它来验证一下。当我在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");
只有当表在处理过程中将var
值放入作用域时,dynamicRow
值才在作用域中。这是通过组件上的各种process*
方法来完成的。
参见setRowIndex(int)
文档:
- 保存所有子体组件的当前状态信息(如下所述)
- 存储新行索引,并将其传递给与此UIData实例关联的DataModel
- 如果新的rowIndex值为-1:
- 如果
var
属性不为null,请删除相应的请求范围属性(如果有)- 重置所有子体组件的状态信息(如下所述)
- 如果新的rowIndex值不是-1:
- 如果
var
属性不为null,则调用getRowData()并将生成的数据对象公开为键为var属性值- 重置所有子体组件的状态信息(如下所述)