How to validate all tabs of rich:tabPanel before form submission?
kenfrommera Aug 10, 2009 1:43 PMHello,
I need to handle Hibernate validation exception when form with rich:tabPanel is being submitted.
I have the following simple form:
<h:form id="organizationEditor">
<h:panelGrid columns="1">
<s:decorate id="nameField" template="edit.xhtml">
<ui:define name="label">Name</ui:define>
<h:inputText id="name" value="#{editedOrganization.name}" required="true">
<a4j:support id="nameCheck" event="onblur" ajaxSingle="true" reRender="nameField" />
<s:validate />
</h:inputText>
</s:decorate>
<!-- Other similar fields-->
</h:panelGrid>
<rich:tabPanel id="tabsPanel" switchType="ajax" immediate="true">
<rich:tab label="Contacts">
<!-- Some optional fields -->
</rich:tab>
<rich:tab label="Supplementary">
<h:panelGrid columns="1">
<!-- Required field -->
<s:decorate id="typeField" template="edit.xhtml">
<ui:define name="type">Type</ui:define>
<h:inputText id="name" value="#{editedOrganization.orgType}" required="true">
<a4j:support id="typeCheck" event="onblur" ajaxSingle="true" reRender="typeField" />
<s:validate />
</h:inputText>
</s:decorate>
</h:panelGrid>
</rich:tab>
</rich:tabPanel>
<h:commandButton action="#{organizationEditor.save}" value="Save" />
<h:commandButton action="#{organizationEditor.cancel}" value="Cancel" immediate="true" />
</h:form>
edit.xhtml is the following:
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html">
<s:label styleClass="name #{invalid?'errors':''}">
<ui:insert name="label"/>
<s:span styleClass="required" rendered="#{required}">*</s:span>
</s:label>
<span class="value #{invalid?'errors':''}">
<s:validateAll>
<ui:insert/>
</s:validateAll>
</span>
<s:message styleClass="error errors"/>
</ui:composition>
Now, when I press the Save button with the first (Contacts
) tab active, without activating the second (Supplementary
) tab and filling all required fields with values, I receive Hibernate validator's exception:
org.hibernate.validator.InvalidStateException with message: validation failed for: com.ims.ipat.core.entity.organizations.Organization
It is correct since NotNull validator is defined for the Organization.orgType field.
But I need to design my application so, that all fields are validated in web, without any exceptions :-)
Could you, please, give me idea how such cases are usually handled?
I'm not very experienced in web interfaces development with JSF and RichFaces, that's why I usually need some help in such common cases :-(