JSF how to restrict validation to open accordion tab -
each of tabs has data table, input , add button. when click add button validation happens on open , closed tabs. see errors closed tabs in open tab. there way make validation occur in open tab.
<p:accordionpanel id="pnl_accord_codetables" dynamic="true" cache="false"> <p:ajax event="tabchange" listener="#{pc_maintenence.ontabchange}" immediate="true"/> <c:foreach items="#{pc_maintenence.codemaintenencetables}" var="codetable"> <p:tab title="#{codetable.tablename}"> <util:datatable_util datatabletemplate="#{codetable}" datatablelist="#{pc_maintenence.getdatatablelist(codetable.tablelist_managedbeanname.concat('.').concat(codetable.tablelist_propertyname))}" datatablelistitem="#{pc_maintenence.getdatatablelistitem(codetable.tablelist_rowitemclassname, codetable)}" actionmethodsbean="#{pc_maintenence}" buildmessagepanel="true"/> </p:tab> </c:foreach> </p:accordionpanel>
this code inside composite
<p:panel id="pnl_add" rendered="#{cc.attrs.datatabletemplate.addrow}"> <ui:repeat value="#{cc.attrs.datatabletemplate.columns}" var="column"> <p:outputlabel styleclass="outputlabel" value="#{column.heading}" for="inputtext" rendered="#{column.inputforaddingrecord}"/> <p:inputtext value="#{(cc.attrs.datatablelistitem)[column.name]}" rendered="#{column.inputforaddingrecord}" id="inputtext" required="#{not empty param[cc.add.clientid] , column.required}" validator="#{column.validate}"/> <div class="clear"> </div> </ui:repeat> </p:panel> <p:panel id="pnl_commandbuttons"> <p:commandbutton stylecl2ass="commandbutton" rendered="#{cc.attrs.datatabletemplate.addrow}" binding="#{cc.add}" action="#{cc.attrs.actionmethodsbean.addrowaction(cc.attrs.datatabletemplate)}" value="add" update="pnl_datatable pnl_add pnl_msg @parent" title="add"> <p:collector value="#{cc.attrs.datatablelistitem}" addto="#{cc.attrs.datatablelist}" /> </p:commandbutton> <p:commandbutton styleclass="commandbutton" rendered="#{cc.attrs.datatabletemplate.addrow or cc.attrs.datatabletemplate.editable}" action="#{cc.attrs.actionmethodsbean.submitaction(cc.attrs.datatabletemplate)}" value="submit" update="pnl_datatable pnl_add pnl_msg @parent" title="submit"> </p:commandbutton> </p:panel>
this validation method inside of columns class
public void validate(facescontext context, uicomponent component, object value) throws validatorexception { resourcebundle resource = (resourcebundle)getmanagedbean("regex"); string pattern = resource.getstring(this.regexname); if(pattern != null){ regexvalidator regexvalidator = new regexvalidator(); regexvalidator.setpattern(pattern); regexvalidator.validate(context, component, value); } }
Comments
Post a Comment