Requirement is to skip field validation conditionally. When user selects add, the form fields should be validated and values added to the table. If edit is clicked, form field validation should be skipped but bean values should be copied to the input fields.
<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 Input composite component
<h:inputText id="fName" value="#{bean.fname}">
<f:validateBean disabled="#{cc.attrs. disableBeanValidation}"/>
</h:inputText>
If user enter's details and selects add, the details are added to the table. If validation errors, we display the error message.
Then user selects edit, the values are copied to the input fields. User selects cancel edit, the values are removed from the input fields. If user selects edit again, we get a index out of bound exception error. Index out of bound exception for name_firstName.
But this does not occur if user selects add and cancel edit is selected. Does it has to do with the view parameter being passed which is null somehow?
javax.faces.FacesException: Unexpected error restoring state for component with id frmAddAuthBuyerBR_inpAuthBuyerBRName_prefix_input. Cause: java.lang.IndexOutOfBoundsException: Index: 0, Size: 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 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 javax.faces.component.UIComponent.visitTree(UIComponent.java:1626) at javax.faces.component.UIForm.visitTree(UIForm.java:371) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1626)