重複的ID錯誤在描述我遇到的問題之前,我會首先給出一些上下文。與更新的Mojarra 2.1.27
環境是JSF,Primefaces 3.5和GlassFish 3.1.2.2。
我正在研究用於編輯數據的應用程序。數據分成幾個表單,每個表單都在tabView的選項卡中。數據模型非常豐富,在某些情況下,有幾個嵌套tabViews。
爲了簡化開發,應用程序具有一個描述表單字段的複合組件。它將字段的標籤,輸入,工具提示和其他圖形組件分組。表單包含幾個這些複合組件。
該應用程序是使用GlassFish 3及其提供的Mojarra(版本2.1.6)設計和編碼的。起初,它廣泛使用JSTL標籤(c:if,c:forEach和c:choose),這對於根據具體情況動態構建頁面內容非常方便。
因此,複合組件具有許多c:if標籤來根據其類型(輸入文本,組合框,日曆等)構建字段。同樣,應用程序最複雜的屏幕(使用3個嵌套tabViews)使用大量c:if和c:choose標籤構建。
隨着Mojarra 2.1.6,應用程序按需要工作。但是在複雜的屏幕上,由於a bug in older Mojarra versions,應用程序的性能非常差。然後我們決定將Mojarra升級到最新的2.1版本,即2.1.27。
由於升級我們遇到問題,最重要的是在表單加載和AJAX更新期間出現重複的ID錯誤。重複的ID總是涉及複合組件的內部組件。看起來複合組件連續兩次使用相同的clientId實例化。例示本部分組件樹如下:
+id: DataDashboard
type: [email protected]
+id: Data_property
type: [email protected]
+id: j_idt1286
type: [email protected]
+id: j_idt1287
type: [email protected]
+id: j_id4
type: [email protected]
+id: j_idt1288
type: [email protected]
+id: j_idt1289
type: [email protected]
+id: j_idt1290
type: <html xmlns="http://www.w3.org/1999/xhtml">
+id: hType <===============
type: [email protected]
+id: lId
type: [email protected]
+id: j_idt1299
type: [email protected]
+id: j_idt1300
type: [email protected]
(...)
+id: j_idt3300
type: [email protected]
+id: j_idt3301
type: [email protected]
+id: j_idt3302
type: <html xmlns="http://www.w3.org/1999/xhtml">
+id: hType <===============
type: [email protected]
閱讀本網站的文章,如this one或BalusC's blog後,我決定擺脫JSTL標記,這可能涉及的問題(但我不能確定);無論如何,這將是「更好」(或者是?)。
所以,與其
<c:if test="#{someCriterion}">
(some stuff)
</c:if>
我外部化(一些東西)在名爲someStuff.xhtml另一個文件,並寫入
<ui:include src="#{someCriterion ? 'someStuff.xhtml' : ''}" />
在測試中使用的標準是複合組件的屬性,會話範圍Bean的屬性或上述標準(函數或三元運算符)的衍生物。
據我所知,我已經使用此方法轉換了所有JSTL標記,並且該應用程序的行爲與轉換之前的行爲相同。不幸的是,這包括重複的ID錯誤。
我也嘗試使用測試用例應用程序複製錯誤,很不幸,我還沒有設法做到這一點。看來,簡單的應用程序工作。
我很迷茫,因爲如何解決這個問題。任何幫助,將不勝感激。
非常感謝。
編輯:加入的局部組件樹。
謝謝你花時間回答我。我會嘗試禁用PSS。我已經嘗試將MyFaces替換爲Mojarra,但我遇到了一些其他問題。毫無疑問,他們將被列在另一個StackOverflow文章中。 – Charlie