jsf 2 - Alternative to Deltaspike Multi-Window Handling in Seam 3 Applikation -
i have problems multi-window handling in appliacation. using conversation scope enable multi window / tab handling in case user opens link (button) in new tab conversation shared between old , new tab.
apache deltaspike has solution (http://deltaspike.apache.org/documentation/#_module_overview) using seam 3 (and jsf 2.1) , don't want migrate deltaspike.
so i'm searching alternative solution without deltaspike or possible use deltaspike , seam 3?
i build solution p:remotecommand , answer: in javascript, how can uniquely identify 1 browser window under same cookiedbased sessionid
i added js template creates unique id each browswer tab stores in window.name. calls p:remotecommand check 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}]); } })
added primefaces remotecommand template called script above.
<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>
and added check action validateds current browser tab / window comparing guid's:
@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; } }
Comments
Post a Comment