0
我試圖獲取值表達式中包含的值。我需要使用它進行一些驗證。當我在HTMLOutput中設置值表達式時,它會顯示在屏幕上。請建議我做錯了什麼?從valueExpression獲取值JSF1.2
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的新手,並沒有做太多的工作。 – Mohit 2013-02-21 07:59:13
我不明白爲什麼你有任何代碼。爲什麼不直接在模型上查找數據? – McDowell 2013-02-21 09:20:38