Primefaces Dialog TabView

1

I have a Dialog where there are 2 tabs, click to display the dialog and alternate between the tabs, after closing if return to TabView it returns with the last tab visited and I need it to return the first tab. I already tried with activeIndex, it works the first time, but if you close and return it again displays with the last tab visited.

Suggestions?

    
asked by anonymous 16.11.2016 / 22:35

2 answers

1

You can try as follows: create a method to open dialog and set the value of activeIndex directly to the bean.

public void abrirDialog() {
    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    UIComponent componente = viewRoot.findComponent("idTabView");
    TabView tabView = (TabView) componente;
    tabView.setActiveIndex(0); //Vai abrir a primeira aba
    RequestContext.getCurrentInstance().update(componente.getClientId());
    RequestContext.getCurrentInstance().execute("PF('widgetVarDialog').show();");
}
    
23.11.2016 / 16:08
1

I was able to solve this method further:

public UIComponent findComponent(final String id) {

        FacesContext context = FacesContext.getCurrentInstance();
        UIViewRoot root = context.getViewRoot();
        final UIComponent[] found = new UIComponent[1];

        root.visitTree(new FullVisitContext(context), new VisitCallback() {
            @Override
            public VisitResult visit(VisitContext context, UIComponent component) {
                if (component.getId().equals(id)) {
                    found[0] = component;
                    return VisitResult.COMPLETE;
                }
                return VisitResult.ACCEPT;
            }
        });

        return found[0];

    }
    
08.12.2016 / 23:13