myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r451779 - in /myfaces: core/branches/jsf12/impl/src/main/tld/entities/ core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/ core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/ shared/branches/3_0_0/core...
Date Sun, 01 Oct 2006 18:29:20 GMT
Author: baranda
Date: Sun Oct  1 11:29:19 2006
New Revision: 451779

URL: http://svn.apache.org/viewvc?view=rev&rev=451779
Log:
Implemented MYFACES-1209 (JSF 1.2) Added "layout" attribute to the panelGroup component

Added:
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java
  (with props)
Modified:
    myfaces/core/branches/jsf12/impl/src/main/tld/entities/standard_panel_group_attributes.xml
    myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
    myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/html/HtmlPanelGroupTagBase.java

Modified: myfaces/core/branches/jsf12/impl/src/main/tld/entities/standard_panel_group_attributes.xml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/tld/entities/standard_panel_group_attributes.xml?view=diff&rev=451779&r1=451778&r2=451779
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/tld/entities/standard_panel_group_attributes.xml
(original)
+++ myfaces/core/branches/jsf12/impl/src/main/tld/entities/standard_panel_group_attributes.xml
Sun Oct  1 11:29:19 2006
@@ -1,4 +1,15 @@
-        <!-- all standard attributes of the panelGroup tag -->
-        &ui_panel_attributes;
-        &html_universal_attributes;
-        &html_event_handler_attributes;
+<!-- all standard attributes of the panelGroup tag -->
+&ui_panel_attributes;
+&html_universal_attributes;
+&html_event_handler_attributes;
+
+<!-- GridRenderer attributes -->
+<attribute>
+    <name>layout</name>
+    <required>false</required>
+    <rtexprvalue>false</rtexprvalue>
+    <description>
+        If the value of the layout is 'block' render the group with a DIV element.
+        Otherwise render a SPAN element (default).
+    </description>
+</attribute>

Added: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java?view=auto&rev=451779
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java
(added)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java
Sun Oct  1 11:29:19 2006
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.renderkit.html;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+import org.apache.shale.test.mock.MockRenderKitFactory;
+import org.apache.shale.test.mock.MockResponseWriter;
+
+import javax.faces.component.html.HtmlOutputText;
+import javax.faces.component.html.HtmlPanelGroup;
+import java.io.StringWriter;
+
+/**
+ * @author Bruno Aranda (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlGroupRendererTest extends AbstractJsfTestCase
+{
+    private static String PANEL_CHILD_TEXT = "PANEL";
+    private static String STYLE_CLASS = "myStyleClass";
+
+    private MockResponseWriter writer ;
+    private HtmlPanelGroup panelGroup;
+
+    public HtmlGroupRendererTest(String name)
+    {
+        super(name);
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        panelGroup = new HtmlPanelGroup();
+
+        HtmlOutputText panelChildOutputText = new HtmlOutputText();
+        panelChildOutputText.setValue(PANEL_CHILD_TEXT);
+        panelGroup.getChildren().add(panelChildOutputText);
+
+        writer = new MockResponseWriter(new StringWriter(), null, null);
+        facesContext.setResponseWriter(writer);
+
+        facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
+        facesContext.getRenderKit().addRenderer(
+                panelGroup.getFamily(),
+                panelGroup.getRendererType(),
+                new HtmlGroupRenderer());
+        facesContext.getRenderKit().addRenderer(
+                panelChildOutputText.getFamily(),
+                panelChildOutputText.getRendererType(),
+                new HtmlTextRenderer());
+
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        writer = null;
+    }
+
+    public void testLayout_Default() throws Exception
+    {
+        assertNull(panelGroup.getLayout());
+
+        panelGroup.setStyleClass(STYLE_CLASS);
+
+        panelGroup.encodeEnd(facesContext);
+        facesContext.renderResponse();
+
+        String output = writer.getWriter().toString();
+
+        assertEquals("<span class=\""+STYLE_CLASS+"\">PANEL</span>", output);
+    }
+
+    public void testLayout_Block() throws Exception
+    {
+        panelGroup.setLayout("block");
+
+        panelGroup.setStyleClass(STYLE_CLASS);
+
+        panelGroup.encodeEnd(facesContext);
+        facesContext.renderResponse();
+
+        String output = writer.getWriter().toString();
+
+        assertEquals("<div class=\""+STYLE_CLASS+"\">PANEL</div>", output);
+    }
+}

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/renderkit/html/HtmlGroupRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java?view=diff&rev=451779&r1=451778&r2=451779
==============================================================================
--- myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
(original)
+++ myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlGroupRendererBase.java
Sun Oct  1 11:29:19 2006
@@ -16,12 +16,12 @@
 package org.apache.myfaces.shared.renderkit.html;
 
 import org.apache.myfaces.shared.renderkit.RendererUtils;
-import org.apache.myfaces.shared.renderkit.html.HTML;
 
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
+import javax.faces.component.html.HtmlPanelGroup;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
 import java.io.IOException;
 
 /**
@@ -33,6 +33,8 @@
 public class HtmlGroupRendererBase
         extends HtmlRenderer 
 {
+    private static final String LAYOUT_BLOCK_VALUE = "block";
+
     public boolean getRendersChildren()
     {
         return true;
@@ -54,11 +56,23 @@
         ResponseWriter writer = context.getResponseWriter();
         boolean span = false;
 
+        // will be SPAN or DIV, depending on the layout attribute value
+        String layoutElement = HTML.SPAN_ELEM;
+
+        HtmlPanelGroup panelGroup = (HtmlPanelGroup) component;
+
+        // if layout is 'block', render DIV instead SPAN
+        String layout = panelGroup.getLayout();
+        if (layout != null && layout.equals(LAYOUT_BLOCK_VALUE))
+        {
+            layoutElement = HTML.DIV_ELEM;
+        }
+
         if(component.getId()!=null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
         {
             span = true;
 
-            writer.startElement(org.apache.myfaces.shared.renderkit.html.HTML.SPAN_ELEM,
component);
+            writer.startElement(layoutElement, component);
 
             HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
 
@@ -68,14 +82,14 @@
         {
             span=HtmlRendererUtils.renderHTMLAttributesWithOptionalStartElement(writer,
                                                                              component,
-                                                                             HTML.SPAN_ELEM,
+                                                                             layoutElement,
                                                                              HTML.COMMON_PASSTROUGH_ATTRIBUTES);
         }
 
         RendererUtils.renderChildren(context, component);
         if (span)
         {
-            writer.endElement(HTML.SPAN_ELEM);
+            writer.endElement(layoutElement);
         }
     }
 

Modified: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/html/HtmlPanelGroupTagBase.java
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/html/HtmlPanelGroupTagBase.java?view=diff&rev=451779&r1=451778&r2=451779
==============================================================================
--- myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/html/HtmlPanelGroupTagBase.java
(original)
+++ myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/html/HtmlPanelGroupTagBase.java
Sun Oct  1 11:29:19 2006
@@ -15,6 +15,10 @@
  */
 package org.apache.myfaces.shared.taglib.html;
 
+import org.apache.myfaces.shared.renderkit.JSFAttr;
+
+import javax.faces.component.UIComponent;
+
 
 /**
  * @author Manfred Geiler (latest modification by $Author$)
@@ -33,4 +37,22 @@
 
     // HTML event handler attributes --> already implemented in HtmlComponentTagBase
 
+    // GroupRenderer specific attributes
+    private String _layout;
+
+    public void release() {
+        super.release();
+        _layout = null;
+    }
+    
+    protected void setProperties(UIComponent component)
+    {
+        super.setProperties(component);
+        setStringProperty(component, JSFAttr.LAYOUT_ATTR, _layout);
+    }
+
+    public void setLayout(String layout)
+    {
+        this._layout = layout;
+    }
 }



Mime
View raw message