You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2007/05/07 11:13:44 UTC

svn commit: r535800 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/renderkit/ core/src/main/java/org/apache/myfaces/tobago/renderkit/html/ core/src/main/java/org/apache/myfaces/tobago/webapp/ core/src/test/java/org/apache/myfa...

Author: lofwyr
Date: Mon May  7 02:13:41 2007
New Revision: 535800

URL: http://svn.apache.org/viewvc?view=rev&rev=535800
Log:
Try to make Tomahawk components runnting inside of Tobago pages.

Added:
    myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Tomahawk.java
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/tomahawk.jsp
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
    myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockRenderKit.java
    myfaces/tobago/trunk/example/sandbox/pom.xml
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/web.xml
    myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java Mon May  7 02:13:41 2007
@@ -56,25 +56,28 @@
     }
     Renderer renderer = null;
     FacesContext facesContext = FacesContext.getCurrentInstance();
-    if ("facelets".equals(family)) {
-      RenderKitFactory rkFactory = (RenderKitFactory)
-      FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
-      RenderKit renderKit = rkFactory.getRenderKit(facesContext, RenderKitFactory.HTML_BASIC_RENDER_KIT);
-      renderer = renderKit.getRenderer(family, rendererType);
-      if (renderer != null) {
-        return new RendererBaseWrapper(renderer);
-      }
-    } else {
+    if (!"facelets".equals(family)) {
       if (rendererType != null) {
         if (resources == null) {
           resources = ResourceManagerFactory.getResourceManager(facesContext);
         }
         renderer = resources.getRenderer(facesContext.getViewRoot(), rendererType);
       }
-      if (renderer == null) {
-        LOG.error("The class which was found by the ResourceManager cannot be "
-            + "found or instantiated: classname='" + rendererType + "'");
+    }
+
+    if (renderer == null) {
+      RenderKitFactory rkFactory = (RenderKitFactory)
+      FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+      RenderKit renderKit = rkFactory.getRenderKit(facesContext, RenderKitFactory.HTML_BASIC_RENDER_KIT);
+      renderer = renderKit.getRenderer(family, rendererType);
+      if (renderer != null) {
+        renderer = new RendererBaseWrapper(renderer);
       }
+    }
+
+    if (renderer == null) {
+      LOG.error("The class which was found by the ResourceManager cannot be "
+          + "found or instantiated: classname='" + rendererType + "'");
     }
 
     return renderer;

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlRendererUtil.java Mon May  7 02:13:41 2007
@@ -39,6 +39,7 @@
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.LayoutInformationProvider;
 import org.apache.myfaces.tobago.renderkit.RenderUtil;
+import org.apache.myfaces.tobago.renderkit.RendererBaseWrapper;
 import org.apache.myfaces.tobago.util.LayoutUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
 
@@ -79,16 +80,19 @@
       } else {
         ResponseWriter writer = facesContext.getResponseWriter();
         startJavascript(writer);
-        writer.write("Tobago.focusId = '" + id + "';");
+        writer.writeText("Tobago.focusId = '" + id + "';", null);
         endJavascript(writer);
       }
     }
   }
 
   public static void prepareRender(FacesContext facesContext, UIComponent component) {
-    createCssClass(facesContext, component);
-    layoutWidth(facesContext, component);
-    layoutHeight(facesContext, component);
+    // xxx find a better way for this question: isTobago or isLayoutable something like that.
+    if (! (ComponentUtil.getRenderer(facesContext, component) instanceof RendererBaseWrapper)) {
+      createCssClass(facesContext, component);
+      layoutWidth(facesContext, component);
+      layoutHeight(facesContext, component);
+    }
   }
 
   public static void prepareInnerStyle(UIComponent component) {

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoResponseWriter.java Mon May  7 02:13:41 2007
@@ -38,6 +38,12 @@
 
 public class TobagoResponseWriter extends ResponseWriter {
 
+  @Override
+  public void write(String string) throws IOException {
+    closeOpenTag();
+    super.write(string);
+  }
+
   private static final Log LOG = LogFactory.getLog(TobagoResponseWriter.class);
 
   private static final Set<String> EMPTY_TAG

Modified: myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockRenderKit.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockRenderKit.java?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockRenderKit.java (original)
+++ myfaces/tobago/trunk/core/src/test/java/org/apache/myfaces/tobago/mock/faces/MockRenderKit.java Mon May  7 02:13:41 2007
@@ -17,6 +17,8 @@
  * limitations under the License.
  */
 
+import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
+
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIData;
 import javax.faces.component.UIInput;
@@ -37,134 +39,126 @@
 public class MockRenderKit extends RenderKit {
 
   public MockRenderKit() {
-      addRenderer(UIData.COMPONENT_FAMILY,
-      "javax.faces.Table", new TestRenderer());
-addRenderer(UIInput.COMPONENT_FAMILY,
-      "TestRenderer", new TestRenderer());
-      addRenderer(UIInput.COMPONENT_FAMILY,
-      "javax.faces.Text", new TestRenderer());
-addRenderer(UIOutput.COMPONENT_FAMILY,
-      "TestRenderer", new TestRenderer());
-      addRenderer(UIOutput.COMPONENT_FAMILY,
-      "javax.faces.Text", new TestRenderer());
-      addRenderer(UIPanel.COMPONENT_FAMILY,
-      "javax.faces.Grid", new TestRenderer());
+    addRenderer(UIData.COMPONENT_FAMILY, "javax.faces.Table", new TestRenderer());
+    addRenderer(UIInput.COMPONENT_FAMILY, "TestRenderer", new TestRenderer());
+    addRenderer(UIInput.COMPONENT_FAMILY, "javax.faces.Text", new TestRenderer());
+    addRenderer(UIOutput.COMPONENT_FAMILY, "TestRenderer", new TestRenderer());
+    addRenderer(UIOutput.COMPONENT_FAMILY, "javax.faces.Text", new TestRenderer());
+    addRenderer(UIPanel.COMPONENT_FAMILY, "javax.faces.Grid", new TestRenderer());
   }
 
-
-  private Map<String,Renderer> renderers = new HashMap<String, Renderer>();
-
+  private Map<String, Renderer> renderers = new HashMap<String, Renderer>();
 
   public void addRenderer(String family, String rendererType,
                           Renderer renderer) {
-      if ((family == null) || (rendererType == null) || (renderer == null)) {
-          throw new NullPointerException();
-      }
-      renderers.put(family + "|" + rendererType, renderer);
+    if ((family == null) || (rendererType == null) || (renderer == null)) {
+      throw new NullPointerException();
+    }
+    renderers.put(family + "|" + rendererType, renderer);
   }
 
-
   public Renderer getRenderer(String family, String rendererType) {
-      if ((family == null) || (rendererType == null)) {
-          throw new NullPointerException();
-      }
-      return (renderers.get(family + "|" + rendererType));
+    if ((family == null) || (rendererType == null)) {
+      throw new NullPointerException();
+    }
+    return (renderers.get(family + "|" + rendererType));
   }
 
 
   public ResponseWriter createResponseWriter(Writer writer,
-               String contentTypeList,
-               String characterEncoding) {
-      return new MockResponseWriter(writer, characterEncoding);
+                                             String contentTypeList,
+                                             String characterEncoding) {
+    return new MockResponseWriter(writer, characterEncoding);
   }
 
   public ResponseStream createResponseStream(OutputStream out) {
-final OutputStream os = out;
-return new ResponseStream() {
-  public void close() throws IOException {
-      os.close();
-  }
-  public void flush() throws IOException {
-      os.flush();
-  }
-  public void write(byte[] b) throws IOException {
-      os.write(b);
-  }
-  public void write(byte[] b, int off, int len) throws IOException {
-      os.write(b, off, len);
-  }
-  public void write(int b) throws IOException {
-      os.write(b);
-  }
+    final OutputStream os = out;
+    return new ResponseStream() {
+      public void close() throws IOException {
+        os.close();
+      }
+
+      public void flush() throws IOException {
+        os.flush();
+      }
+
+      public void write(byte[] b) throws IOException {
+        os.write(b);
+      }
+
+      public void write(byte[] b, int off, int len) throws IOException {
+        os.write(b, off, len);
+      }
+
+      public void write(int b) throws IOException {
+        os.write(b);
+      }
     };
   }
 
-
   public ResponseStateManager getResponseStateManager() {
-return null;
+    return null;
   }
 
-
   class TestRenderer extends Renderer {
 
-public TestRenderer() {}
+    public TestRenderer() {
+    }
 
-      public void decode(FacesContext context, UIComponent component) {
+    public void decode(FacesContext context, UIComponent component) {
 
-          if ((context == null) || (component == null)) {
-              throw new NullPointerException();
-          }
-
-          if (!(component instanceof UIInput)) {
-              return;
-          }
-          UIInput input = (UIInput) component;
-          String clientId = input.getClientId(context);
-          // System.err.println("decode(" + clientId + ")");
+      if ((context == null) || (component == null)) {
+        throw new NullPointerException();
+      }
 
-          // Decode incoming request parameters
-          Map params = context.getExternalContext().getRequestParameterMap();
-          if (params.containsKey(clientId)) {
-              // System.err.println("  '" + input.currentValue(context) +
-              //                    "' --> '" + params.get(clientId) + "'");
-              input.setSubmittedValue(params.get(clientId));
-          }
+      if (!(component instanceof UIInput)) {
+        return;
+      }
+      UIInput input = (UIInput) component;
+      String clientId = input.getClientId(context);
+      // System.err.println("decode(" + clientId + ")");
 
+      // Decode incoming request parameters
+      Map params = context.getExternalContext().getRequestParameterMap();
+      if (params.containsKey(clientId)) {
+        // System.err.println("  '" + input.currentValue(context) +
+        //                    "' --> '" + params.get(clientId) + "'");
+        input.setSubmittedValue(params.get(clientId));
       }
 
-      public void encodeBegin(FacesContext context, UIComponent component)
-          throws IOException {
+    }
 
-          if ((context == null) || (component == null)) {
-              throw new NullPointerException();
-          }
-          ResponseWriter writer = context.getResponseWriter();
-          writer.write
-              ("<text id='" + component.getClientId(context) + "' value='" +
-               component.getAttributes().get("value") + "'/>\n");
+    public void encodeBegin(FacesContext context, UIComponent component)
+        throws IOException {
 
+      if ((context == null) || (component == null)) {
+        throw new NullPointerException();
       }
+      ResponseWriter writer = context.getResponseWriter();
+      writer.startElement(HtmlConstants.INPUT, component);
+      writer.writeAttribute("id", component.getClientId(context), null);
+      writer.writeAttribute("value", null, "value");
+      writer.endElement(HtmlConstants.INPUT);
 
-      public void encodeChildren(FacesContext context, UIComponent component)
-          throws IOException {
+    }
 
-          if ((context == null) || (component == null)) {
-              throw new NullPointerException();
-          }
+    public void encodeChildren(FacesContext context, UIComponent component)
+        throws IOException {
 
+      if ((context == null) || (component == null)) {
+        throw new NullPointerException();
       }
 
-      public void encodeEnd(FacesContext context, UIComponent component)
-          throws IOException {
+    }
 
-          if ((context == null) || (component == null)) {
-              throw new NullPointerException();
-          }
+    public void encodeEnd(FacesContext context, UIComponent component)
+        throws IOException {
 
+      if ((context == null) || (component == null)) {
+        throw new NullPointerException();
       }
 
-  }
-
-
+    }
 
+  }
 }

Modified: myfaces/tobago/trunk/example/sandbox/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/pom.xml?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/pom.xml (original)
+++ myfaces/tobago/trunk/example/sandbox/pom.xml Mon May  7 02:13:41 2007
@@ -85,6 +85,11 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.myfaces.tomahawk</groupId>
+      <artifactId>tomahawk</artifactId>
+      <version>1.1.5</version>
+    </dependency>
+    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.11</version>

Added: myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Tomahawk.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Tomahawk.java?view=auto&rev=535800
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Tomahawk.java (added)
+++ myfaces/tobago/trunk/example/sandbox/src/main/java/org/apache/myfaces/tobago/example/sandbox/Tomahawk.java Mon May  7 02:13:41 2007
@@ -0,0 +1,20 @@
+package org.apache.myfaces.tobago.example.sandbox;
+
+import org.apache.myfaces.custom.schedule.model.SimpleScheduleModel;
+
+/**
+ * User: lofwyr
+ * Date: 03.05.2007 18:42:54
+ */
+public class Tomahawk {
+
+  private SimpleScheduleModel schedule;
+
+  public SimpleScheduleModel getSchedule() {
+    return schedule;
+  }
+
+  public void setSchedule(SimpleScheduleModel schedule) {
+    this.schedule = schedule;
+  }
+}

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/faces-config.xml Mon May  7 02:13:41 2007
@@ -35,4 +35,10 @@
     <managed-bean-scope>session</managed-bean-scope>
   </managed-bean>
 
+  <managed-bean>
+    <managed-bean-name>tomahawk</managed-bean-name>
+    <managed-bean-class>org.apache.myfaces.tobago.example.sandbox.Tomahawk</managed-bean-class>
+    <managed-bean-scope>session</managed-bean-scope>
+  </managed-bean>
+
 </faces-config>

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/web.xml?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/WEB-INF/web.xml Mon May  7 02:13:41 2007
@@ -33,6 +33,28 @@
     <url-pattern>/faces/*</url-pattern>
   </filter-mapping>
 
+  <filter>
+	<filter-name>MyFacesExtensionsFilter</filter-name>
+	<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
+    <init-param>
+        <param-name>maxFileSize</param-name>
+        <param-value>2m</param-value>
+    </init-param>
+</filter>
+
+<!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages  -->
+<filter-mapping>
+    <filter-name>MyFacesExtensionsFilter</filter-name>
+    <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
+    <servlet-name>FacesServlet</servlet-name>
+</filter-mapping>
+
+<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.)  -->
+<filter-mapping>
+    <filter-name>MyFacesExtensionsFilter</filter-name>
+    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
+</filter-mapping>
+
 <!--  workaround (e.g. for Oracle AS 10.1.2.0.0)-->
   <listener>
     <listener-class>org.apache.myfaces.tobago.webapp.TobagoServletContextListener</listener-class>

Modified: myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp?view=diff&rev=535800&r1=535799&r2=535800
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp (original)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/navigation.jsp Mon May  7 02:13:41 2007
@@ -24,8 +24,7 @@
   <tc:page label="Screenshot" id="page"
            width="200px" height="800px">
     <f:facet name="layout">
-      <tc:gridLayout margin="5px"
-                     rows="fixed;fixed;fixed;fixed;fixed;fixed;*"/>
+      <tc:gridLayout margin="5px" rows="fixed;fixed;fixed;fixed;fixed;fixed;fixed;*"/>
     </f:facet>
 
     <tc:link link="separator.jsp" label="separator.jsp" target="View"/>
@@ -39,6 +38,8 @@
     <tc:link link="tree-editor.jsp" label="tree-editor.jsp" target="View"/>
 
     <tc:link link="inputSlider.jsp" label="inputSlider.jsp" target="View"/>
+
+    <tc:link link="tomahawk.jsp" label="tomahawk.jsp" target="View"/>
 
     <tc:cell/>
   </tc:page>

Added: myfaces/tobago/trunk/example/sandbox/src/main/webapp/tomahawk.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/sandbox/src/main/webapp/tomahawk.jsp?view=auto&rev=535800
==============================================================================
--- myfaces/tobago/trunk/example/sandbox/src/main/webapp/tomahawk.jsp (added)
+++ myfaces/tobago/trunk/example/sandbox/src/main/webapp/tomahawk.jsp Mon May  7 02:13:41 2007
@@ -0,0 +1,35 @@
+<%--
+ * 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.
+--%>
+
+<%@ taglib uri="http://myfaces.apache.org/tobago/sandbox" prefix="tcs" %>
+<%@ taglib uri="http://myfaces.apache.org/tobago/component" prefix="tc" %>
+<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
+<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
+
+<f:view>
+  <tc:page label="Sandbox - Test to use Non-Tobago components" id="page"
+           width="1200px" height="1000px">
+    <f:facet name="layout">
+      <tc:gridLayout margin="10px" columns="*;*" rows="*" border="1" />
+    </f:facet>
+
+    <t:schedule value="#{tomahawk.schedule}"/>
+
+    <t:inputHtml value="test"/>
+
+  </tc:page>
+</f:view>