You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2011/11/23 17:58:19 UTC

svn commit: r1205491 - in /myfaces/extensions/cdi/trunk: examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/r...

Author: struberg
Date: Wed Nov 23 16:58:17 2011
New Revision: 1205491

URL: http://svn.apache.org/viewvc?rev=1205491&view=rev
Log:
EXTCDI-242 improve ClientSideWindowHandler and sample

Added:
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ClientSideWindowHandlerWindowConfig.java   (with props)
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/layout.xhtml   (with props)
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/resources/
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/resources/css/
      - copied from r1202385, myfaces/extensions/cdi/trunk/examples/jsf-playground/hello_myfaces-codi_jsf20/src/main/webapp/resources/css/
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/resources/images/
      - copied from r1202385, myfaces/extensions/cdi/trunk/examples/jsf-playground/hello_myfaces-codi_jsf20/src/main/webapp/resources/images/
Modified:
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/js/windowhandler.js
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi.xhtml
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi1.xhtml
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleList.xhtml
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleListEntry.xhtml
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage.xhtml
    myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage2.xhtml
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/ClientConfig.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html

Added: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ClientSideWindowHandlerWindowConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ClientSideWindowHandlerWindowConfig.java?rev=1205491&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ClientSideWindowHandlerWindowConfig.java (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ClientSideWindowHandlerWindowConfig.java Wed Nov 23 16:58:17 2011
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.examples.jsf20.config;
+
+import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.config.WindowContextConfig;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Specializes;
+
+/**
+ * In case of using the ClientSideWindowHandler we mandate for using windowIds in the URLs
+ */
+@ApplicationScoped
+@Specializes
+public class ClientSideWindowHandlerWindowConfig extends WindowContextConfig
+{
+    private static final long serialVersionUID = -4094949435815088068L;
+
+    @Override
+    public boolean isAddWindowIdToActionUrlsEnabled()
+    {
+        return true;
+    }
+
+
+}

Propchange: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/java/org/apache/myfaces/examples/jsf20/config/ClientSideWindowHandlerWindowConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/js/windowhandler.js
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/js/windowhandler.js?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/js/windowhandler.js (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/resources/META-INF/resources/js/windowhandler.js Wed Nov 23 16:58:17 2011
@@ -94,10 +94,23 @@ function applyOnClick()
     }
 }
 
+function assertWindowId() {
+    var freshWindow = window.name.length < 1;
+    if (freshWindow) {
+        url = urlWithoutWindowId(window.location.href);
+        window.name = "window";
+        window.location = url;
+    }
+}
+
+
 window.onload = function()
 {
     if (isHtml5())
     {
         applyOnClick();
     }
+
+    // this ensures that even without the ClientSideWindowHandler
+    assertWindowId();
 }

Added: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/layout.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/layout.xhtml?rev=1205491&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/layout.xhtml (added)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/layout.xhtml Wed Nov 23 16:58:17 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:ui="http://java.sun.com/jsf/facelets">
+    <f:view>
+        <ui:insert name="metadata"/>
+        <h:head>
+            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+            <link href="#{resource['images:favicon.ico']}" rel="shortcut icon" type="image/vnd.microsoft.icon"/>
+            <link href="#{resource['css:theme.css']}" rel="stylesheet" type="text/css" media="all"/>
+            <h:outputScript library="javax.faces" name="jsf.js"/>
+            <h:outputScript library="js" name="windowhandler.js"/>
+            <ui:insert name="header"></ui:insert>
+            <title><h:outputText value="MyFaces CODI - "/><ui:insert name="title"></ui:insert></title>
+        </h:head>
+        <h:body class="#{theme.section}">
+            <div id="codi">
+                <div id="home">
+                    <div id="mainContainer">
+                        <div id="headContainer">
+                            <div id="mainNavigation">
+                                <h:form rendered="#{user.loggedIn}">
+                                    <h:outputText value="#{user.viewName}"/>&#0160;&#0160;<h:outputText value="#{user.msisdn}"/>&#0160;
+                                    <h:commandLink value="logout" action="#{user.logout}" />
+                                </h:form>
+                            </div><!-- /MainNavigation -->
+                        </div><!-- /headContainer -->
+
+                        <!-- real content on the white-board. -->
+                        <div id="contentContainer">
+                            <h:messages id="globalMessagesPanel" globalOnly="true" errorClass="errorMessage"
+                                        infoClass="infoMessage" warnClass="warnMessage" fatalClass="errorMessage"/>
+                            <ui:insert name="content"/>
+                        </div><!-- /contentContainer -->
+                    </div>
+                </div>
+            </div>
+        </h:body>
+    </f:view>
+
+</html>

Propchange: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/WEB-INF/templates/layout.xhtml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi.xhtml?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi.xhtml Wed Nov 23 16:58:17 2011
@@ -26,41 +26,39 @@
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-    <head>
-        <title>CODI JSF 2.0 Client Side WindowHandler Demo</title>
-        <h:outputScript library="javax.faces" name="jsf.js"/>
-        <h:outputScript library="js" name="windowhandler.js"/>
-    </head>
-
-    <body>
-        <h1 style="color:red">Dev-Demo (purpose: only for tests during development)</h1>
-
-        <p>
-            This example shows you the powerful functions of the new
-            client side window handler.
-        </p>
-        <p>
-            It determines the identity of a browsers window or tab by
-            using the <b>window.name</b> to hold a unique identifier.
-            This windowId will be transfered to the server with a small
-            JavaScript page which gets served upfront to the original
-            page. You don't even need to add the windowId parameter
-            to the URL!
-        </p>
-
-        <p>
-            The current windowId is: <h:outputText value="#{currentWindowContext.id}"/><br/><br/>
-        </p>
-
-        <h:form>
-            <h:commandLink value="next" action="next"/>
-        </h:form>
-        <h:outputText value="#{conversationDemoBean1.value}"/><br/>
-
-        <h:link value="ViewAccessScoped example" outcome="viewAccessBeanPage.xhtml"/><br/>
-        <h:outputLink value="noCodiPage.xhtml">Page without Codi scoped beans</h:outputLink><br/>
-        <h:outputLink value="listsample/sampleList.xhtml">List sample</h:outputLink>
-        
-        <h:messages globalOnly="true"/>
-    </body>
+    <ui:composition template="/WEB-INF/templates/layout.xhtml">
+        <ui:define name="title">CODI JSF 2.0 Client Side WindowHandler Demo</ui:define>
+
+        <ui:define name="content">
+            <h1 style="color:red">Dev-Demo (purpose: only for tests during development)</h1>
+
+            <p>
+                This example shows you the powerful functions of the new
+                client side window handler.
+            </p>
+            <p>
+                It determines the identity of a browsers window or tab by
+                using the <b>window.name</b> to hold a unique identifier.
+                This windowId will be transfered to the server with a small
+                JavaScript page which gets served upfront to the original
+                page. You don't even need to add the windowId parameter
+                to the URL!
+            </p>
+
+            <p>
+                The current windowId is: <h:outputText value="#{currentWindowContext.id}"/><br/><br/>
+            </p>
+
+            <h:form>
+                <h:commandLink value="next" action="next"/>
+            </h:form>
+            <h:outputText value="#{conversationDemoBean1.value}"/><br/>
+
+            <h:link value="ViewAccessScoped example" outcome="viewAccessBeanPage.xhtml"/><br/>
+            <h:outputLink value="noCodiPage.xhtml">Page without Codi scoped beans</h:outputLink><br/>
+            <h:outputLink value="listsample/sampleList.xhtml">List sample</h:outputLink>
+
+            <h:messages globalOnly="true"/>
+        </ui:define>
+    </ui:composition>
 </html>

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi1.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi1.xhtml?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi1.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/helloMyFacesCodi1.xhtml Wed Nov 23 16:58:17 2011
@@ -26,13 +26,15 @@
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-    <head><title>CODI JSF 2.0 Demo</title></head>
+<ui:composition template="/WEB-INF/templates/layout.xhtml">
+    <ui:define name="title">CODI JSF 2.0 Demo</ui:define>
 
-    <body>
+    <ui:define name="content">
         <h:form>
             <h:commandLink value="back" action="/helloMyFacesCodi.xhtml"/>
         </h:form>
         <h:outputText value="#{conversationDemoBean1.value}"/>
         <h:messages globalOnly="true"/>
-    </body>
-</html>
\ No newline at end of file
+    </ui:define>
+</ui:composition>
+</html>

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleList.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleList.xhtml?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleList.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleList.xhtml Wed Nov 23 16:58:17 2011
@@ -1,6 +1,6 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-<!--
+<!DOCTYPE html
+        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><!--
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,36 +18,32 @@
  * specific language governing permissions and limitations
  * under the License.
 -->
-
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-    <head><title>CODI JSF 2.0 List Demo</title></head>
-
-    <body>
-        <f:view>
-
-            <p>
-                The current windowId is: <h:outputText value="#{currentWindowContext.id}"/><br/><br/>
-            </p>
-            
-            <h:form>
-                <h3>A sample List </h3>
-                <h:dataTable value="#{sampleList.entryIds}" id="list" var="entryId">
-                    <h:column>
-                        <h:link outcome="sampleListEntry">
-                            <h:outputText value="#{entryId}"/>
-                            <f:param name="entryId" value="#{entryId}"/>
-                        </h:link>
-                    </h:column>
-                </h:dataTable>
-
-            </h:form>
-
-            <h:messages globalOnly="true"/>
+<ui:composition template="/WEB-INF/templates/layout.xhtml">
+    <ui:define name="title">CODI JSF 2.0 List Demo</ui:define>
 
-        </f:view>
-    </body>
-</html>
\ No newline at end of file
+    <ui:define name="content">
+        <p>
+            The current windowId is: <h:outputText value="#{currentWindowContext.id}"/><br/><br/>
+        </p>
+        <h:form>
+            <h3>A sample List </h3>
+            <h:dataTable value="#{sampleList.entryIds}" id="list" var="entryId">
+                <h:column>
+                    <h:link outcome="sampleListEntry">
+                        <h:outputText value="#{entryId}"/>
+                        <f:param name="entryId" value="#{entryId}"/>
+                    </h:link>
+                </h:column>
+            </h:dataTable>
+
+        </h:form>
+
+        <h:messages globalOnly="true"/>
+    </ui:define>
+</ui:composition>
+</html>

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleListEntry.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleListEntry.xhtml?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleListEntry.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/listsample/sampleListEntry.xhtml Wed Nov 23 16:58:17 2011
@@ -24,34 +24,35 @@
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-    <head><title>CODI JSF 2.0 List Demo</title></head>
+<ui:composition template="/WEB-INF/templates/layout.xhtml">
+    <ui:define name="title">CODI JSF 2.0 List Demo</ui:define>
 
-    <f:metadata>
-        <f:viewParam name="entryId" value="#{sampleListEntry.id}"/>
-    </f:metadata>
-
-    <body>
-        <f:view>
-            <p>
-                The current windowId is: <h:outputText value="#{currentWindowContext.id}"/><br/><br/>
-            </p>
-                    
-            <h:form>
-                <h3>A sample List Entry</h3>
-                <h:panelGrid columns="2">
-                    <h:outputLabel value="id"/>
-                    <h:outputText value="#{sampleListEntry.id}"/>
-
-                    <h:outputLabel value="value"/>
-                    <h:inputText value="#{sampleListEntry.value}"/>
-                </h:panelGrid>
-
-                <h:commandButton action="#{sampleListEntry.back}" value="back"/>
-                <h:commandButton action="#{sampleListEntry.reload}" value="reload"/>
-            </h:form>
-
-            <h:messages globalOnly="true"/>
-
-        </f:view>
-    </body>
-</html>
\ No newline at end of file
+    <ui:define name="metadata">
+        <f:metadata>
+            <f:viewParam name="entryId" value="#{sampleListEntry.id}"/>
+        </f:metadata>
+    </ui:define>
+
+    <ui:define name="content">
+        <p>
+            The current windowId is: <h:outputText value="#{currentWindowContext.id}"/><br/><br/>
+        </p>
+
+        <h:form>
+            <h3>A sample List Entry</h3>
+            <h:panelGrid columns="2">
+                <h:outputLabel value="id"/>
+                <h:outputText value="#{sampleListEntry.id}"/>
+
+                <h:outputLabel value="value"/>
+                <h:inputText value="#{sampleListEntry.value}"/>
+            </h:panelGrid>
+
+            <h:commandButton action="#{sampleListEntry.back}" value="back"/>
+            <h:commandButton action="#{sampleListEntry.reload}" value="reload"/>
+        </h:form>
+
+        <h:messages globalOnly="true"/>
+    </ui:define>
+</ui:composition>
+</html>

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage.xhtml?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage.xhtml Wed Nov 23 16:58:17 2011
@@ -26,11 +26,10 @@
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-    <head><title>CODI JSF 2.0 Demo</title></head>
-
-    <body>
-        <f:view>
+    <ui:composition template="/WEB-INF/templates/layout.xhtml">
+        <ui:define name="title">CODI JSF 2.0 Demo</ui:define>
 
+        <ui:define name="content">
             <h:form>
                 <h3>values of ViewAccessScoped bean 1:</h3>
                 <h:panelGrid columns="2">
@@ -55,6 +54,6 @@
 
             <h:messages globalOnly="true"/>
 
-        </f:view>
-    </body>
-</html>
\ No newline at end of file
+        </ui:define>
+    </ui:composition>
+</html>

Modified: myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage2.xhtml
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage2.xhtml?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage2.xhtml (original)
+++ myfaces/extensions/cdi/trunk/examples/jsf-playground/clientside_windowhandler_jsf20/src/main/webapp/viewAccessBeanPage2.xhtml Wed Nov 23 16:58:17 2011
@@ -26,10 +26,10 @@
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:ui="http://java.sun.com/jsf/facelets">
 
-    <head><title>CODI JSF 2.0 Demo</title></head>
+    <ui:composition template="/WEB-INF/templates/layout.xhtml">
+        <ui:define name="title">CODI JSF 2.0 Demo</ui:define>
 
-    <body>
-        <f:view>
+        <ui:define name="content">
             <h:form>
                 <h3>values of ViewAccessScoped bean 1:</h3>
                 <h:panelGrid columns="2">
@@ -49,6 +49,6 @@
                                 
                 <h:messages globalOnly="true"/>
             </h:form>
-        </f:view>
-    </body>
-</html>
\ No newline at end of file
+        </ui:define>
+    </ui:composition>
+</html>

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/ClientConfig.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/ClientConfig.java?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/ClientConfig.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/api/src/main/java/org/apache/myfaces/extensions/cdi/jsf/api/config/ClientConfig.java Wed Nov 23 16:58:17 2011
@@ -20,12 +20,15 @@ package org.apache.myfaces.extensions.cd
 
 import org.apache.myfaces.extensions.cdi.core.api.projectstage.ProjectStage;
 import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
+import org.apache.myfaces.extensions.cdi.jsf.api.request.RequestTypeResolver;
 
 import javax.enterprise.context.SessionScoped;
+import javax.faces.context.FacesContext;
 import javax.inject.Inject;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
+import java.util.Map;
 
 /**
  * Contains information about whether the user has
@@ -48,6 +51,10 @@ public class ClientConfig implements Ser
     @Inject
     private ProjectStage projectStage;
 
+    @Inject
+    private RequestTypeResolver requestTypeResolver;
+
+
     /**
      * The location of the default windowhandler resource
      */
@@ -119,4 +126,48 @@ public class ClientConfig implements Ser
         windowHandlerHtml = sb.toString();
         return windowHandlerHtml;
     }
+
+    /**
+     * Users can overload this method to define in which scenarios a request should result
+     * in an 'intercepted' page with proper windowId detection. This can e.g. contain
+     * blacklisting some userAgents.
+     * By default the following User-Agents will be served directly:
+     * <ul>
+     *     <li>.*bot.*</li>
+     *     <li>.*Bot.*</li>
+     *     <li>.*Slurp.*</li>
+     *     <li>.*Crawler.*</li>
+     * </ul>
+     * @return <code>true</code> if the Request should get 'intercepted' and the intermediate
+     *        windowhandler.html page should get rendered first. By returning <code>false</code>
+     *        the requested page will get rendered intermediately.
+     */
+    public boolean isClientSideWindowHandlerRequest(FacesContext facesContext)
+    {
+        if (!isJavaScriptEnabled())
+        {
+            return false;
+        }
+
+        Map<String, String[]> requestHeaders = facesContext.getExternalContext().getRequestHeaderValuesMap();
+
+        if (requestHeaders != null &&
+            requestHeaders.containsKey("User-Agent"))
+        {
+            String[] userAgents = requestHeaders.get("User-Agent");
+            String userAgent = userAgents.length > 0 ? userAgents[0] : null;
+
+            if (userAgent.indexOf("bot")     >= 0 || // Googlebot, etc
+                userAgent.indexOf("Bot")     >= 0 || // BingBot, etc
+                userAgent.indexOf("Slurp")   >= 0 || // Yahoo Slurp
+                userAgent.indexOf("Crawler") >= 0    // various other Crawlers
+               )
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
 }

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf/impl/scope/conversation/ClientSideWindowHandler.java Wed Nov 23 16:58:17 2011
@@ -48,10 +48,12 @@ public class ClientSideWindowHandler ext
     private static final long serialVersionUID = 5293942986187078113L;
 
     private static final String WINDOW_ID_COOKIE_SUFFIX = "-codiWindowId";
+    private static final String CODI_REQUEST_TOKEN = "codiToken";
+
     private static final String UNINITIALIZED_WINDOW_ID_VALUE = "uninitializedWindowId";
     private static final String WINDOW_ID_REPLACE_PATTERN = "$$windowIdValue$$";
     private static final String NOSCRIPT_URL_REPLACE_PATTERN = "$$noscriptUrl$$";
-    private static final String NOSCRIPT_PARAMETER = "noscript";
+    private static final String NOSCRIPT_PARAMETER = "codiNoWh";
 
     @Inject
     private ClientConfig clientConfig;
@@ -117,7 +119,7 @@ public class ClientSideWindowHandler ext
      */
     public void beforeLifecycleExecute(FacesContext facesContext)
     {
-        if (!isClientSideWindowHandlerRequest())
+        if (!isClientSideWindowHandlerRequest(facesContext))
         {
             return;
         }
@@ -161,11 +163,11 @@ public class ClientSideWindowHandler ext
         }
     }
 
-    private boolean isClientSideWindowHandlerRequest()
+    private boolean isClientSideWindowHandlerRequest(FacesContext facesContext)
     {
         // no POST request and javascript enabled
         // NOTE that for POST-requests the windowId is saved in the state (see WindowContextIdHolderComponent)
-        return !this.requestTypeResolver.isPostRequest() && this.clientConfig.isJavaScriptEnabled();
+        return !this.requestTypeResolver.isPostRequest() && clientConfig.isClientSideWindowHandlerRequest(facesContext);
     }
 
     private boolean isNoscriptRequest(ExternalContext externalContext)
@@ -254,16 +256,9 @@ public class ClientSideWindowHandler ext
 
     private String getWindowIdFromCookie(ExternalContext externalContext)
     {
-        String cookieName = getEncodedPathName(externalContext) + WINDOW_ID_COOKIE_SUFFIX;
+        String cookieName = getRequestToken(externalContext) + WINDOW_ID_COOKIE_SUFFIX;
         Cookie cookie = (Cookie) externalContext.getRequestCookieMap().get(cookieName);
 
-        if (cookie == null)
-        {
-            // if the current request went to a welcome page, we should only consider the contextPath
-            cookieName = getEncodedContextPath(externalContext) + WINDOW_ID_COOKIE_SUFFIX;
-            cookie = (Cookie) externalContext.getRequestCookieMap().get(cookieName);
-        }
-
         if (cookie != null)
         {
             return cookie.getValue();
@@ -272,32 +267,15 @@ public class ClientSideWindowHandler ext
         return null;
     }
 
-    private String getEncodedPathName(ExternalContext externalContext)
+    private String getRequestToken(ExternalContext externalContext)
     {
-        StringBuilder sb = new StringBuilder();
-
-        String contextPath = externalContext.getRequestContextPath();
-        if (contextPath != null)
+        String requestToken = externalContext.getRequestParameterMap().get(CODI_REQUEST_TOKEN);
+        if (requestToken != null)
         {
-            sb.append(contextPath);
+            return requestToken;
         }
 
-        String servletPath = externalContext.getRequestServletPath();
-        if (servletPath != null)
-        {
-            sb.append(servletPath);
-        }
-
-        String pathInfo = externalContext.getRequestPathInfo();
-        if (pathInfo != null)
-        {
-            sb.append(pathInfo);
-        }
-
-        // remove all "/", because they can be different in JavaScript
-        String pathName = sb.toString().replace("/", "");
-
-        return JsfUtils.encodeURLParameterValue(pathName, externalContext);
+        return "";
     }
 
     private String getEncodedContextPath(ExternalContext externalContext)

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html?rev=1205491&r1=1205490&r2=1205491&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html (original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf-module/impl/src/main/resources/static/windowhandler.html Wed Nov 23 16:58:17 2011
@@ -117,8 +117,42 @@ function replaceContent() {
     }
 }
 
+function setUrlParam(baseUrl, paramName, paramValue) {
+    var query = baseUrl;
+    var vars = query.split(/&|\?/g);
+    var newQuery = "";
+    var iParam = 0;
+    var paramFound = false;
+    for (var i=0; vars != null && i < vars.length; i++) {
+        var pair = vars[i].split("=");
+        if (pair.length == 1) {
+            newQuery = pair[0];
+        }
+        else {
+            if (pair[0] != paramName) {
+                var amp = iParam++ > 0 ? "&" : "?";
+                newQuery =  newQuery + amp + pair[0] + "=" + pair[1];
+            }
+            else {
+                paramFound = true;
+                var amp = iParam++ > 0 ? "&" : "?";
+                newQuery =  newQuery + amp + paramName + "=" + paramValue;
+            }
+        }
+    }
+
+    if (!paramFound) {
+        var amp = iParam++ > 0 ? "&" : "?";
+        newQuery =  newQuery + amp + paramName + "=" + paramValue;
+    }
+    return newQuery;
+}
+
+
 replaceContent();
 
+
+
 window.onload = function() {
 
     loadCss(true);
@@ -150,13 +184,12 @@ window.onload = function() {
     expdt.setTime(expdt.getTime()+(2*1000));
     var expires = "; expires="+expdt.toGMTString();
 
-    // include pathName (without "/"s) in cookie name
-    var pathName = encodeURIComponent(window.location.pathname.replace(/\//g, ""));
+    var requestToken = Math.floor(Math.random()*100000001);
+    var newUrl = setUrlParam(window.location.href, "codiToken", requestToken);
 
-    document.cookie = pathName + '-codiWindowId=' + windowId + expires;
+    document.cookie = requestToken + '-codiWindowId=' + windowId + expires;
 
-    // resubmit the page but now with the cookie
-    window.location.reload();
+    window.location = newUrl;
 }
 </script>