Primefaces Dialog Tabview

Asked

Viewed 260 times

1

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

Suggestions?

  • 1

    Did you solve it? I have the same problem.

  • 6

    Just so I understand, you asked yourself if you’ve solved?

2 answers

1

I was able to solve with more this method:

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];

    }

1


You can try as follows: create a method to open the dialog and set the value of activeIndex directly by 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();");
}
  • I am having a Nullpointer when calling the method to display as explained. Have you any idea what may be happening ?

  • My problem is here that does not find the component.

  • @Jeremiah Santos sometimes I need to use an auxiliary method to search in Viewroot, as you said. Normally, findComponent is enough. Thank you for the information.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.