2014-01-29 63 views
1

我能夠使用使用primefaces的push方法。我如何控制p:socket超時事件及其時間? 我的意思是,我如何設置p:socket超時?另外, p:socket會話超時時如何捕獲事件?設置PrimeFaces套接字超時

我正在使用以下與p:socket相關的部分代碼語句。

// XHMTL

<p:socket onMessage="handleMessage" channel="/chat" autoConnect="false" 
    widgetVar="subscriber" /> 

//豆

RequestContext.getCurrentInstance().execute("subscriber.connect('/" + usernamePushContext+ "')"); 

回答

0

我已經發現,包括兩個步驟的溶液中。 首先,您必須將servlet參數添加到web.xml並執行PushContextListener

<param-name>org.atmosphere.cpr.CometSupport.maxInactiveActivity</param-name> 
    <param-value>9000</param-value> 

其次,在每個onDisconnect()方法調用中,您應該檢查傳輸值。

@Override 
    public void onDisconnect(Object arg0) { 

String transport = ((AtmosphereRequest) arg0).getRequest().getParameter 
(HeaderConfig.X_ATMOSPHERE_TRANSPORT); 

根據傳輸值,可以觸發斷開連接過程。

 if (transport != null && 
     (transport.equalsIgnoreCase(HeaderConfig.DISCONNECT) || 
     transport.equalsIgnoreCase(HeaderConfig.LONG_POLLING_TRANSPORT) 
    )) { 

    // close operation... 
    }