getClientWindow() issue

Hi All,

I have a problem with using getClientWindow() in portlet application.

I created a simple Portlet Application in Designer, where I have a portlet with default.xhtml file.
When I browse this file with the this link (http://IP:port/testm/Portletm/default.xhtml), I can reach the clientWindow.getId() property.

On the xhtml file I have a simple async command button with this source code.

        FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    ClientWindow clientWindow = externalContext.getClientWindow();
    error("Default.view - clientWindow.getId(): " + clientWindow.getId());

But, when I browse this xhtml with this link (http://IP:port/meta/default/testm___portletm/0000008805?wmp8805.wmp_ws=maximized), the clientWindow is NULL.

What can be wrong or what is missing?

Thanks in advance,
Zsolt

Hope below docs link helps.

https://docs.oracle.com/javaee/7/api/javax/faces/lifecycle/ClientWindow.html

Below code can be used to attach clientWindow to context

LifecycleFactory factory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
javax.faces.lifecycle.Lifecycle lfc=factory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
lfc.attachWindow(this.getFacesContext());

Hi Iman,

Your code is working, but I want to use this solution to identify the browser tabs.
Now when I click on then async command button or refresh the browser(F5) the actual window will be attached again to the factory.

Is it possible to check whether the window is already attached or not?

Thanks,