2014-12-02 35 views
0

我在我的appliiacation中有多窗口處理問題。 我目前使用對話範圍來啓用多窗口/標籤處理,但是如果用戶在新選項卡中打開鏈接(按鈕),對話將在新舊標籤之間共享。替代Deltaspike多窗口處理seam 3應用

Apache Deltaspike有一個解決方案(http://deltaspike.apache.org/documentation/#_module_overview),但我已經使用Seam 3(和JSF 2.1),並且不想遷移到Deltaspike。

所以我正在尋找一個沒有Deltaspike的替代解決方案,或者是否有可能使用Deltaspike和Seam 3?

+0

如果可以的話,升級到JSF-2.2:現在 – kolossus 2014-12-02 16:33:18

+0

處理多個窗口,所有我後已經在JSF 2.2中讀到過這樣的消息:如果用戶在新選項卡中打開鏈接/按鈕,則無法工作,因爲兩個選項卡中的窗口ID都是相同的。無論如何,JSF 2.2的更新目前是不可能的。 – user1127860 2014-12-04 11:57:46

+0

JSF 2.2只提供一個ClientWindow,但它不管理它的範圍。使用DeltaSpike而不是Seam3。 DeltaSpike是這條道路上的未來,而且非常棒! – 2014-12-05 22:50:43

回答

0

我建立與對一個解決方案:remoteCommand和這樣的回答:In javascript, how can I uniquely identify one browser window from another which are under the same cookiedbased sessionId

我加入這個JS給我的模板,在window.name每個browswer標籤創建一個唯一的ID的存儲。然後調用一個p:remoteCommand檢查GUID:

$(window).load(function() { 
    // ---------------------- 
    var GUID = function() { 
     // ------------------ 
     var S4 = function() { 
      return (Math.floor(Math.random() * 0x10000 /* 65536 */ 
      ).toString(16)); 
     }; 
     return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()); 
    }; 

    if (!window.name.match(/^GUID-/)) { 
     window.name = "GUID-" + GUID(); 
    } 

    if ($('#guid_form\\:server_guid').text().length == 0 || 
      $('#guid_form\\:server_guid').text() != window.name) { 
     checkGuid([{name:'guid', value:window.name}]); 
    } 
}) 

增加了Primefaces remoteCommand到我的模板是由上面的腳本調用。

<h:form id="guid_form"> 
    <h:outputText value="#{checkTabAction.guid}" id="server_guid"/> 
    <p:remoteCommand name="checkGuid" actionListener="#{checkTabAction.checkGuid}" process="@this" partialSubmit="true" /> 
</h:form> 

並且增加了通過比較validateds當前瀏覽器標籤/窗口的檢查行動的GUID:

@ConversationScoped 
@Named(value = "checkTabAction") 
public class CheckTabAction implements Serializable { 

    private static final long serialVersionUID = 1L; 

    @Inject 
    private Logger log; 

    private String guid = null; 

    public void checkGuid() { 
     Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); 
     String guid = params.get("guid").toString(); 

     if (this.guid == null) { 
      this.guid = guid; 
     } 

     if (!StringUtils.equals(this.guid, guid)) { 
      log.info("New tab detected!"); 
      throw new NonexistentConversationException("New tab detected!"); 
     } 
    } 

    public String getGuid() { 
     return guid; 
    } 

}