Updated Branches:
  refs/heads/master 68fbe33d8 -> fb8ef1c51

DELTASPIKE-495 dsWindowContext

 (+ cleanup of javadoc and unused parts)


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/fb8ef1c5
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/fb8ef1c5
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/fb8ef1c5

Branch: refs/heads/master
Commit: fb8ef1c517a8f58664ccbd75fdd5d7bbb7f2098e
Parents: 68fbe33
Author: gpetracek <gpetra...@apache.org>
Authored: Sun Jan 5 20:46:24 2014 +0100
Committer: gpetracek <gpetra...@apache.org>
Committed: Sun Jan 5 20:58:44 2014 +0100

----------------------------------------------------------------------
 .../scope/window/WindowContextProducer.java     |   2 +
 .../component/window/WindowIdComponent.java     |  32 ++++
 .../window/WindowIdHolderComponent.java         | 158 -------------------
 .../WindowIdHolderComponentHtmlRenderer.java    |  85 ----------
 .../component/window/WindowIdHtmlRenderer.java  |  79 ++++++++++
 .../impl/scope/window/DefaultClientWindow.java  |   1 -
 6 files changed, 113 insertions(+), 244 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fb8ef1c5/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextProducer.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextProducer.java
 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextProducer.java
index 46d8d31..aadd9da 100644
--- 
a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextProducer.java
+++ 
b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/scope/window/WindowContextProducer.java
@@ -22,6 +22,7 @@ import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Produces;
 import javax.inject.Inject;
+import javax.inject.Named;
 
 import org.apache.deltaspike.core.impl.scope.DeltaSpikeContextExtension;
 import org.apache.deltaspike.core.spi.scope.window.WindowContext;
@@ -39,6 +40,7 @@ public class WindowContextProducer
     private DeltaSpikeContextExtension deltaSpikeContextExtension;
 
     @Produces
+    @Named("dsWindowContext")
     @Dependent
     public WindowContext getWindowContext()
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fb8ef1c5/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdComponent.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdComponent.java
 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdComponent.java
new file mode 100644
index 0000000..304204b
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdComponent.java
@@ -0,0 +1,32 @@
+/*
+ * 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.deltaspike.jsf.impl.component.window;
+
+import javax.faces.component.FacesComponent;
+import javax.faces.component.UIOutput;
+
+
+/**
+ * {@link WindowIdHtmlRenderer} will render a small script needed for 
ajax-requests
+ */
+@FacesComponent(WindowIdComponent.COMPONENT_TYPE)
+public class WindowIdComponent extends UIOutput
+{
+    public static final String COMPONENT_TYPE = 
"org.apache.deltaspike.WindowIdHolder";
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fb8ef1c5/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponent.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponent.java
 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponent.java
deleted file mode 100644
index 4ec76c5..0000000
--- 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponent.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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.deltaspike.jsf.impl.component.window;
-
-import javax.faces.component.FacesComponent;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIOutput;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-
-/**
- * UI Component holder for the windowId in case of post-backs.
- * We store this component as direct child in the ViewRoot
- * and evaluate it's value on postbacks.
- */
-@FacesComponent(WindowIdHolderComponent.COMPONENT_TYPE)
-public class WindowIdHolderComponent extends UIOutput
-{
-    public static final String COMPONENT_TYPE = 
"org.apache.deltaspike.WindowIdHolder";
-
-    private static final Logger logger = 
Logger.getLogger(WindowIdHolderComponent.class.getName());
-
-    private String windowId;
-
-    /**
-     * Default constructor might be invoked by the jsf implementation
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    public WindowIdHolderComponent()
-    {
-    }
-
-    /**
-     * Constructor which creates the holder for the given window-id
-     * @param windowId current window-id
-     */
-    public WindowIdHolderComponent(String windowId)
-    {
-        this.windowId = windowId;
-    }
-
-    /**
-     * Needed for server-side window-handler and client-side window handler 
for supporting postbacks
-     */
-    public static void addWindowIdHolderComponent(FacesContext facesContext, 
String windowId)
-    {
-        if (windowId == null || windowId.length() == 0)
-        {
-            return;
-        }
-
-        UIViewRoot uiViewRoot = facesContext.getViewRoot();
-
-        if (uiViewRoot == null)
-        {
-            return;
-        }
-
-        WindowIdHolderComponent existingWindowIdHolder = 
getWindowIdHolderComponent(uiViewRoot);
-        if (existingWindowIdHolder != null)
-        {
-            if (!windowId.equals(existingWindowIdHolder.getWindowId()))
-            {
-                logger.log(Level.FINE, "updating WindowIdHolderComponent from 
%1 to %2",
-                        new Object[]{existingWindowIdHolder.getId(), 
windowId});
-
-                existingWindowIdHolder.changeWindowId(windowId);
-            }
-            return;
-        }
-        else
-        {
-            // add as first child
-            uiViewRoot.getChildren().add(0, new 
WindowIdHolderComponent(windowId));
-        }
-    }
-
-    public static WindowIdHolderComponent 
getWindowIdHolderComponent(UIViewRoot uiViewRoot)
-    {
-        List<UIComponent> uiComponents = uiViewRoot.getChildren();
-
-        // performance improvement - don't change - see EXTCDI-256 :
-        for (int i = 0, size = uiComponents.size(); i < size; i++)
-        {
-            UIComponent uiComponent = uiComponents.get(i);
-            if (uiComponent instanceof WindowIdHolderComponent)
-            {
-                //in this case we have the same view-root
-                return (WindowIdHolderComponent) uiComponent;
-            }
-        }
-
-        return null;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Object saveState(FacesContext facesContext)
-    {
-        Object[] values = new Object[2];
-        values[0] = super.saveState(facesContext);
-        values[1] = windowId;
-        return values;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void restoreState(FacesContext facesContext, Object state)
-    {
-        if (state == null)
-        {
-            return;
-        }
-
-        Object[] values = (Object[]) state;
-        super.restoreState(facesContext, values[0]);
-
-        windowId = (String) values[1];
-    }
-
-    /**
-     * @return the current windowId
-     */
-    public String getWindowId()
-    {
-        return windowId;
-    }
-
-    void changeWindowId(String windowId)
-    {
-        this.windowId = windowId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fb8ef1c5/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponentHtmlRenderer.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponentHtmlRenderer.java
 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponentHtmlRenderer.java
deleted file mode 100644
index 89b8e7a..0000000
--- 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHolderComponentHtmlRenderer.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.deltaspike.jsf.impl.component.window;
-
-import javax.faces.application.ResourceDependencies;
-import javax.faces.application.ResourceDependency;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.FacesRenderer;
-import javax.faces.render.Renderer;
-import java.io.IOException;
-
-import org.apache.deltaspike.core.api.provider.BeanProvider;
-import org.apache.deltaspike.core.spi.scope.window.WindowContext;
-
-
-/**
- * HtmlRenderer for our dsWindowId hidden field.
- * This gets used for post requests.
- */
-@FacesRenderer(componentFamily = WindowIdHolderComponent.COMPONENT_FAMILY,
-        rendererType = WindowIdHolderComponent.COMPONENT_TYPE)
-@ResourceDependencies( {
-        @ResourceDependency(library = "deltaspike", name = "windowhandler.js", 
target = "head"),
-        @ResourceDependency(library = "javax.faces", name = "jsf.js", target = 
"head") } )
-public class WindowIdHolderComponentHtmlRenderer extends Renderer
-{
-    private volatile WindowContext windowContext;
-
-
-    /**
-     * Write a simple hidden field into the form.
-     * This might change in the future...
-     * @param context
-     * @param component
-     * @throws IOException
-     */
-    @Override
-    public void encodeBegin(FacesContext context, UIComponent component) 
throws IOException
-    {
-        super.encodeBegin(context, component);
-
-        String windowId = getWindowContext().getCurrentWindowId();
-
-        ResponseWriter writer = context.getResponseWriter();
-        writer.startElement("script", component);
-        writer.writeAttribute("type", "text/javascript", null);
-        writer.write("window.deltaspikeJsWindowId=" + windowId + ";");
-
-        writer.endElement("script");
-    }
-
-    private WindowContext getWindowContext()
-    {
-        if (windowContext == null)
-        {
-            synchronized (this)
-            {
-                if (windowContext == null)
-                {
-                    windowContext = 
BeanProvider.getContextualReference(WindowContext.class);
-                }
-            }
-        }
-
-        return windowContext;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fb8ef1c5/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
new file mode 100644
index 0000000..8ef0645
--- /dev/null
+++ 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/component/window/WindowIdHtmlRenderer.java
@@ -0,0 +1,79 @@
+/*
+ * 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.deltaspike.jsf.impl.component.window;
+
+import javax.faces.application.ResourceDependencies;
+import javax.faces.application.ResourceDependency;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.FacesRenderer;
+import javax.faces.render.Renderer;
+import java.io.IOException;
+
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.spi.scope.window.WindowContext;
+
+@FacesRenderer(componentFamily = WindowIdComponent.COMPONENT_FAMILY, 
rendererType = WindowIdComponent.COMPONENT_TYPE)
+@ResourceDependencies( {
+        @ResourceDependency(library = "deltaspike", name = "windowhandler.js", 
target = "head"),
+        @ResourceDependency(library = "javax.faces", name = "jsf.js", target = 
"head") } )
+public class WindowIdHtmlRenderer extends Renderer
+{
+    private volatile WindowContext windowContext;
+
+    /**
+     * 'deltaspikeJsWindowId' will be used to:
+     * Write a simple hidden field into the form.
+     * This might change in the future...
+     * @param context
+     * @param component
+     * @throws IOException
+     */
+    @Override
+    public void encodeBegin(FacesContext context, UIComponent component) 
throws IOException
+    {
+        super.encodeBegin(context, component);
+
+        String windowId = getWindowContext().getCurrentWindowId();
+
+        ResponseWriter writer = context.getResponseWriter();
+        writer.startElement("script", component);
+        writer.writeAttribute("type", "text/javascript", null);
+        writer.write("window.deltaspikeJsWindowId=" + windowId + ";");
+
+        writer.endElement("script");
+    }
+
+    private WindowContext getWindowContext()
+    {
+        if (windowContext == null)
+        {
+            synchronized (this)
+            {
+                if (windowContext == null)
+                {
+                    windowContext = 
BeanProvider.getContextualReference(WindowContext.class);
+                }
+            }
+        }
+
+        return windowContext;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fb8ef1c5/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
----------------------------------------------------------------------
diff --git 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
index dcc7262..725007e 100644
--- 
a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
+++ 
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/scope/window/DefaultClientWindow.java
@@ -112,7 +112,6 @@ public class DefaultClientWindow implements ClientWindow
 
         if (facesContext.isPostback())
         {
-            // for POST we read the windowId from the WindowIdHolderComponent 
in our ViewRoot
             return getPostBackWindowId(facesContext);
         }
 

Reply via email to