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);
}
You can let it refresh the entire view instead:
with
The
immediate="true"will skip processing (and validation) of all input components which doesn’t haveimmediate="true".Alternatively, a piece of JavaScript to reload the page should also do:
Update as per the comments you want a partial request, then just use ajax:
with
Because the
executeis set to@this(which is already the default value by the way, so you can omit it), it won’t process the entire form.