You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by me...@apache.org on 2022/04/01 11:39:37 UTC

[myfaces] branch 2.3.x updated: JSF provides a encodeBegin() and an encodeEnd() method on a Renderer. MyFaces currently performs "begin tag" and "end tag" encoding in the encodeEnd(), which breaks any vendor-neutral path for extensibility. This patch moves the "begin tag" encoding logic to the encodeBegin() function so the renderkit can be extended without needed to extend myfaces classes explicitly, but instead be called through the standard JSF api to start a tag. (#233)

This is an automated email from the ASF dual-hosted git repository.

melloware pushed a commit to branch 2.3.x
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/2.3.x by this push:
     new 8c677df  JSF provides a encodeBegin() and an encodeEnd() method on a Renderer. MyFaces currently performs "begin tag" and "end tag" encoding in the encodeEnd(), which breaks any vendor-neutral path for extensibility. This patch moves the "begin tag" encoding logic to the encodeBegin() function so the renderkit can be extended without needed to extend myfaces classes explicitly, but instead be called through the standard JSF api to start a tag. (#233)
8c677df is described below

commit 8c677df59a37feaf41d012b6a09d0c5871fedf30
Author: glynn leininger <gl...@hotmail.com>
AuthorDate: Fri Apr 1 06:39:30 2022 -0500

    JSF provides a encodeBegin() and an encodeEnd() method on a Renderer. MyFaces currently performs "begin tag" and "end tag" encoding in the encodeEnd(), which breaks any vendor-neutral path for extensibility. This patch moves the "begin tag" encoding logic to the encodeBegin() function so the renderkit can be extended without needed to extend myfaces classes explicitly, but instead be called through the standard JSF api to start a tag. (#233)
    
    Co-authored-by: glynn.leininger <gl...@emoneyusa.com>
---
 .../renderkit/html/HtmlCheckboxRendererBase.java   | 30 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java b/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
index aa6e9b3..3c07583 100644
--- a/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
+++ b/shared/src/main/java/org/apache/myfaces/shared/renderkit/html/HtmlCheckboxRendererBase.java
@@ -54,7 +54,8 @@ public class HtmlCheckboxRendererBase extends HtmlRenderer
 
     private static final String EXTERNAL_TRUE_VALUE = "true";
 
-    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+    @Override
+    public void encodeBegin(FacesContext facesContext, UIComponent uiComponent)
             throws IOException
     {
         org.apache.myfaces.shared.renderkit.RendererUtils.checkParamValidity(facesContext, uiComponent, null);
@@ -78,7 +79,9 @@ public class HtmlCheckboxRendererBase extends HtmlRenderer
         }
         else if (uiComponent instanceof UISelectMany)
         {
-            renderCheckboxList(facesContext, (UISelectMany) uiComponent);
+            // let the current impl do what it does in encodeEnd do nothing here just don't want exception
+            // throw if it is this case
+            log.finest("encodeBegin() doing nothing intentionally for UISelectMany");
         }
         else
         {
@@ -86,6 +89,24 @@ public class HtmlCheckboxRendererBase extends HtmlRenderer
                     + uiComponent.getClass().getName());
         }
     }
+    
+    @Override
+    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
+    {
+        if (uiComponent instanceof UISelectBoolean)
+        {
+            ResponseWriter writer = facesContext.getResponseWriter();
+            writer.endElement(HTML.INPUT_ELEM);
+        }
+        else if (uiComponent instanceof UISelectMany)
+        {
+            renderCheckboxList(facesContext, (UISelectMany) uiComponent);
+        }
+        else
+        {
+            throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
+        }
+    }
 
     public void renderCheckboxList(FacesContext facesContext,
             UISelectMany selectMany) throws IOException
@@ -466,7 +487,10 @@ public class HtmlCheckboxRendererBase extends HtmlRenderer
             writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
         }
         
-        writer.endElement(HTML.INPUT_ELEM);
+        if (uiComponent instanceof UISelectMany)
+        {
+            writer.endElement(HTML.INPUT_ELEM);
+        }
 
         return itemId;
     }