1 Reply Latest reply on Nov 10, 2011 9:13 AM by bpiepers

    TabPanel form validation


      Hi all,


      Have read a couple of topics on this issue but can't seem to find the solution for my problem.


      We have a tabPanel with 6 tabs. The tabPanel is put in a form with buttons to go to the next and previous tabs (along with other buttons to save etc.). The fields on the tabs use rich:beanValidator tags and also the bean that is bound to the form has validators (@AssertTrue) that are not bound to any field. What I see is that beanValidators (whether or not bound to a field) are properly fired when clicking the "Next" button but are not invoked when clicking a tab. Here's an example:


      <h:form id="relationForm" styleClass="editForm">
                          <rich:tabPanel switchType="ajax" id="tabPanel" selectedTab="#{registrationBean.currentTab}" styleClass="tabGeneral" >
                              <rich:tab label="#{msg['label.tab.general']}" id="#{registrationBean.registrationTabs[0].id}" name="#{registrationBean.registrationTabs[0]}" immediate="true" reRender="actionButtons" >
                                  <ui:include src="relation_general.xhtml"  />
                                  <f:setPropertyActionListener target="#{registrationBean.currentTab}" value="#{registrationBean.registrationTabs[0]}" />
                              <!-- Bank info -->
                              <rich:tab label="#{msg['label.tab.bank']}" id="#{registrationBean.registrationTabs[1].id}" name="#{registrationBean.registrationTabs[1]}" reRender="actionButtons">
                                  <ui:include src="relation_bank.xhtml"  />
                                  <f:setPropertyActionListener target="#{registrationBean.currentTab}" value="#{registrationBean.registrationTabs[1]}" />
      //                         (other tabs)
                          <a4j:outputPanel id="actionButtons">
                              <h:commandButton id="prevButton" action="#{registrationBean.previousTab}" value="#{msg['action.registration.previous']}" 
                                  rendered="#{registrationBean.showPrevButton and !registrationBean.readonly}" />                    
                              <h:commandButton id="nextbutton" action="#{registrationBean.nextTab}" value="#{msg['action.registration.next']}"  
                                  rendered="#{registrationBean.showNextButton  and !registrationBean.readonly}" />
                               //(other buttons)


      The code behind the registrationBean.previousTab and registrationBean.nextTab is not really interesting enough to post. It just sets the next or previous tab based on the available tabs. So again: how can I invoke the validations on the bean (bean validators) when clicking a tab (not the next or previous button)?


      Thanks in advance for any help.

        • 1. Re: TabPanel form validation

          A small addition:


          I have now tried to explicitly call the annotated validators on the bean and doing that, errormessages are indeed shown on the screen. However, the tabPanel still switches to the next tab. I now have this in the tab tag:



               <rich:tab label="#{msg['label.tab.general']}" id="#{registrationBean.registrationTabs[0].id}" name="#{registrationBean.registrationTabs[0]}" action="#{registrationBean.setCurrentTab}" immediate="true" reRender="actionButtons">
                    <ui:include src="relation_general.xhtml"  />
                    <f:param name="clickedTab" value="#{registrationBean.registrationTabs[0]}"/>

          In the backingbean, I call a validate method that fills the FacesContext with JSF Messages if an error occurs and sets the current tab to the selected tab if no error occured:



          if (isValid(relation)) {
                      // Get the clicked tab from the request parameters.
                      String tab = JSFUtil.getRequestParameter("clickedTab");
                      if (tab != null && !"".equals(tab)) {


          I have tried switch type ajax and server (on the tabPanel level, not on the tabs themselves). but there doesn't seem to be any difference.