2013-02-19 29 views
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"); 

回答

0

var價值dynamicRow只有在範圍上,當加工過程中table其放入範圍。這由組件上的各種process*方法完成。

參見setRowIndex(int)文檔:

  • 保存所有的後續組件的當前狀態信息(如下所述)。
  • 存儲新行索引,並將其傳遞給與此UIData實例關聯的DataModel。
  • 如果新的rowIndex值爲-1:
    • 如果var屬性不爲空,刪除相應的請求範圍屬性(如果有的話)。
    • 重置所有後代組件的狀態信息(如下所述)。
  • 如果新的rowIndex值不是-1:
    • 如果var屬性不爲空,調用getRowData()和暴露所得數據對象作爲其關鍵是 了var屬性的請求範圍屬性值。
    • 重置所有後代組件的狀態信息(如下所述)。
+0

請你提出一些例子嗎?我是JSF的新手,並沒有做太多的工作。 – Mohit 2013-02-21 07:59:13

+0

我不明白爲什麼你有任何代碼。爲什麼不直接在模型上查找數據? – McDowell 2013-02-21 09:20:38