我在這裏使用我的項目JSF 1.2和標記<a4j:support>
。如何重新生成由dataTable使用Ajax動態生成的inputText
那麼,我在這裏用一個<h:dataTable />
在屏幕上打印一張財務費用清單,用戶可以隨時插入新費用或編輯現有費用,這些費用字段的值(金額,餘額,值)正在inputTexts組件中顯示。
由於我使用的是<h:dataTable />
,它的inputTexts是自動生成的,所以它創建了動態id的動態inputTexts。我看了看網頁的HTML源代碼和JSF用來生成一個的ID格局動態的方法是這樣的:
id="formTemplate:tableForm:0:inputTextValue" ;
id="formTemplate:tableForm:1:inputTextValue" ;
id="formTemplate:tableForm:2:inputTextValue"
而在XHTML頁面我DataTable中使用的代碼是這樣的:
<h:inputText id="inputTextValue" value="#{item.value}" label="Value" styleClass="field" size="9" readonly="true" dir="RTL" style="font-size:12px;width:170px">
我的業務規則的工作原理是:當用戶鍵入的東西在inputTextBalance它調用的onblur它會自動將在該領域「值」的其他價值的事件,但更新此inputTextValue我需要做的在我的面板(panelDataTable)reRender,所以它reRender整個dataTable(dataTable是在面板內)。
<h:inputText id="inputTextBalance" value="#{item.balance}" dir="RTL">
<f:convertNumber currencyCode="BRL" type="currency" />
<a4j:support event="onblur" reRender="panelDataTable" ajaxSingle="true" action="#{expenses.update}"/>
</h:inputText>
既然說到了麻煩,我需要做的是重新描繪只有inputTextValue而不是面板,但這些字段是動態生成的,我無法到達那裏的ID。就像我以前說過,這是JSF用來生成領域
id="formTemplate:tableForm:0:inputTextValue" ;
id="formTemplate:tableForm:1:inputTextValue" ;
id="formTemplate:tableForm:2:inputTextValue"
但是,當我在reRender屬性使用這些ID的,阿賈克斯的日誌返回我這個消息的ID的模式:
18:23:57,208 WARN [AjaxContext] Target component for id formTemplate:tableForm:0:inputTextValue not found
我試過,但我得到了同樣的錯誤信息:reRender="#{rich:clientId('inputTextValue')}"
這裏最奇怪的是,它爲我輸入的該消息沒有找到,但在HTML源代碼,他的ID inputText的是一樣的我已經推薦給reRender。
有沒有人在這裏已經delt這個問題?對我有何建議?
謝謝!
嘿感謝你的小費,但它沒有工作,組件的id是在HTML頁面中正確的,但阿賈克斯的日誌顯示相同的消息錯誤:18:23:57,208 WARN [AjaxContext] id formTemplate的目標組件:tableForm:0:inputTextValue找不到 – Andrew 2014-09-22 21:18:36
如果「tableForm」是'h:dataTable'的確切ID? – 2014-09-22 21:36:19
是的 我猜這是一個Ajax問題,它無法識別動態組件。我的意思是,我完全按照你所說的,組件的id在HTML源代碼中是正確的,並且Ajax無法找到組件。 –
Andrew
2014-09-22 21:51:40