-
Available since OmniFaces 2.3
The <o:skipValidators>
taghandler allows the developer to entirely skip validation when executing an UICommand
or ClientBehaviorHolder
action. This taghandler must be placed inside an UICommand
or ClientBehaviorHolder
component (client behavior holder components are those components supporting <f:ajax>
).
Usage
For example, when adding a new row to the data table, you'd like to not immediately validate all empty rows.
<h:form>
<h:dataTable value="#{bean.items}" var="item">
<h:column>
<h:inputText value="#{item.value}" required="true" />
</h:column>
</h:dataTable>
<h:commandButton value="add new row" action="#{bean.add}">
<o:skipValidators />
</h:commandButton>
<h:commandButton value="save all data" action="#{bean.save}" />
<h:messages />
</h:form>
Note that converters will still run and that model values will still be updated. This behavior is by design.
Demo
Please add new items
When adding a new item while there are empty required fields, you'll see that required validation is skipped, and that submitted values will end up in model (they are not cleared out after re-render).
Demo source code
<h3>Please add new items</h3>
<p>
When adding a new item while there are empty required fields,
you'll see that required validation is skipped,
and that submitted values will end up in model (they are not cleared out after re-render).
</p>
<h:form>
<h:dataTable id="table" value="#{skipValidatorsBean.items}" var="item">
<h:column>
<h:inputText id="value" value="#{item.value}" required="true" requiredMessage="This is required!" />
<h:message for="value" />
</h:column>
</h:dataTable>
<h:commandButton value="add item" action="#{skipValidatorsBean.add}">
<f:ajax execute="@form" render="table" />
<o:skipValidators />
</h:commandButton>
<h:commandButton value="save">
<f:ajax execute="@form" render="@form" />
</h:commandButton>
<h:outputText value="OK!" rendered="#{facesContext.postback and not facesContext.validationFailed}" />
</h:form>
package org.omnifaces.showcase.taghandlers;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Named;
import org.omnifaces.cdi.ViewScoped;
import org.omnifaces.showcase.model.ExampleEntity;
@Named
@ViewScoped
public class SkipValidatorsBean implements Serializable {
private List<ExampleEntity> items;
@PostConstruct
public void init() {
items = new ArrayList<>();
add();
}
public void add() {
items.add(new ExampleEntity());
}
public List<ExampleEntity> getItems() {
return items;
}
}
Documentation & Sources