要求是有條件地跳過字段驗證。當用戶選擇添加時,應該驗證表單字段並將值添加到表中。 如果單擊編輯,應該跳過表單字段驗證,但應將bean值複製到輸入字段。有條件跳過驗證JSF
<composite:nameInput id="name" value="#{buyer.name}"
disableBeanValidation ="#{param['skipBeanValidation']}"/>
<h:commandLink action="#{buyerBacking.cancelEdit}" value="cancel"/>
<h:dataTable value="#{bean.list}">
<h:commandLink value="Edit" action="#{buyerBacking.edit}">
<f:param name="skipBeanValidation" value="true" />
</h:commandLink>
</h:dataTable>
<h:commandLink id="add" action="#{buyerBacking.add}"/>
名稱輸入複合組件
如果用戶輸入的信息並選擇添加,詳細信息添加到表中。 如果驗證錯誤,我們會顯示錯誤消息。
然後用戶選擇編輯,將值複製到輸入字段。 用戶選擇取消編輯,將從輸入字段中刪除值。 如果用戶再次選擇編輯,我們會得到一個索引超出界限的異常錯誤。爲name_firstName索引超出界限的異常。
但是,如果用戶選擇添加和取消編輯,則不會發生這種情況。 它是否與待傳遞的視圖參數無關?
javax.faces.FacesException:意外的錯誤恢復組件的ID爲frmAddAuthBuyerBR_inpAuthBuyerBRName_prefix_input的狀態。原因:java.lang.IndexOutOfBoundsException:索引:0,大小:0. at com.sun.faces.application.view.StateManagementStrategyImpl $ 2.visit(StateManagementStrategyImpl.java:272) at com.sun.faces.component.visit .FullVisitContext.invokeVisitCallback(FullVisitContext.java:151) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) at javax .faces.component.UIComponent.visitTree(UIComponent.java:1626) at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java:163) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1626 ) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) at j javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) at javax.faces.component.UINamingContainer.visitTree(UINamingContainer.java: 163) 在javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) 在javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) 在javax.faces.component.UIComponent.visitTree( UIComponent.java:1626) 在javax.faces.component.UIForm.visitTree(UIForm.java:371) 在javax.faces.component.UIComponent.visitTree(UIComponent.java:1626)
我已更新我的問題中的代碼。我的編碼方式與您的建議相同,但在問題中提到,選擇取消,然後選擇編輯導致綁定異常的索引輸出。 – user679526
堆棧跟蹤將會有所幫助。 – BalusC
添加了堆棧跟蹤。請讓我知道是否需要額外的信息。即使我將禁用的值硬編碼爲true。它僅適用於第一次。當單擊取消然後編輯時,即使禁用爲真,驗證也會發生。對於Cancel方法,我返回一個空字符串。 – user679526