Question

I am using an accordion panel with three tabs.

Each tab has required fields and <p:ajax> tags for accordionPanel:

<p:ajax event="tabChange" update=":contentForm:growl"/>
<p:ajax event="tabClose" update=":contentForm:growl"/>

By default all tabs are closed. When I click to open any tab, it performs vaidation of all inputs in all tabs.

How do I skip field validation and do ajax query during open/close tab?

(I need an Ajax query to save opened tabs indexes to Bean: activeIndex="#{tabBean.activeTabs}")

Was it helpful?

Solution

I have resolved this problem. I have created saver-class:

import javax.faces.event.AjaxBehaviorEvent;
import org.primefaces.component.accordionpanel.AccordionPanel;

public class ActiveIndexSaver {
     private String activeTabs = "-1,0";

     public String getActiveTabs() {
         return activeTabs;
     }

     public void setActiveTabs(String activeTabs) {
         this.activeTabs = activeTabs;
     }

     public void saveIndexes(AjaxBehaviorEvent abe){
         AccordionPanel accordion = (AccordionPanel)abe.getComponent();
         activeTabs = accordion.getActiveIndex();
     }
}

After that I wrote Inject of the bean above to page-bean and getter for him:

@Inject
private ActiveIndexSaver activeIndexSaver;
....
public ActiveIndexSaver getActiveIndexSaver() {
    return activeIndexSaver;
}

And finally, html:

<p:accordionPanel ... activeIndex="#{tabBean.activeIndexSaver.activeTabs}">
     <p:ajax event="tabChange" immediate="true" listener="#{tabBean.activeIndexSaver.saveIndexes}"/>
     <p:ajax event="tabClose" immediate="true" listener="#{tabBean.activeIndexSaver.saveIndexes}"/>
     ......
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top