2014-12-02 54 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; 
    } 

}