CASE: the form contains input text for entering department name (can't be null or blank), and drop down list for selecting parent department (can be null), when entering data, and pressing clear, the clear method in backing bean works fine as expected, but when not entering data and pressing clear, the bean validation for not blank on the name works and validation message appears, and i want to disable the validation in case of clearing.
View Code:
Department Name:<h:outputLabel>Parent Department:</h:outputLabel> <ice:selectOneMenu id="parentDepartment" value="#{department.selectedParentDepartment}"> <f:selectItem/> <f:selectItems value="#{departmentBean.departmentList}" var="dept" itemLabel="#{dept.name}" itemValue="#{dept.id}" /> </ice:selectOneMenu> <h:message for="parentDepartment" style="color:red" /> <ice:panelGroup> <h:commandLink value="Add New" action="#{departmentBean.addOrUpdateDepartment}" /> <h:commandLink value="Add New" actionListener="#{departmentBean.clear}" /> </ice:panelGroup>Bean Validation:
@NotBlank(message = "{name.required}") @Size(max = 25, message = "{long.value}") @Column(name = "name", length = 25, nullable = false) private String name;Backing Bean Method:
public void clear() { setDepartmentObj(new Department()); setSelectedParentDepartment(0); }