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

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 7fd4e9c  EMPIREDB-305 Allow InputControls to render the value wrapper 
tag.
7fd4e9c is described below

commit 7fd4e9c692a0ae3d10858f1d5e38a3f790225e0b
Author: Rainer Döbele <[email protected]>
AuthorDate: Wed Sep 18 12:00:45 2019 +0200

    EMPIREDB-305
    Allow InputControls to render the value wrapper tag.
---
 .../apache/empire/jsf2/components/ControlTag.java  | 12 +----
 .../apache/empire/jsf2/components/InputTag.java    | 36 ++------------
 .../apache/empire/jsf2/components/ValueTag.java    | 56 ++++++++++------------
 .../apache/empire/jsf2/controls/InputControl.java  | 52 +++++++++++++++++++-
 4 files changed, 81 insertions(+), 75 deletions(-)

diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
index 2b7b1da..2e98857 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
@@ -209,18 +209,10 @@ public class ControlTag extends UIInput implements 
NamingContainer
                 valInfo = helper.getValueInfo(context); // Oops, should not 
come here 
 
             String styleClass = helper.getTagStyleClass("eInpDis");
-            String tooltip = 
helper.getValueTooltip(helper.getTagAttributeString("title"));
+            String tooltip = 
helper.getValueTooltip(helper.getTagAttributeValue("title"));
 
             // render components
-            ResponseWriter writer = context.getResponseWriter();
-            writer.startElement(this.tagName, this);
-            if (StringUtils.isNotEmpty(styleClass))
-                writer.writeAttribute("class", styleClass, null);
-            if (StringUtils.isNotEmpty(tooltip))
-                writer.writeAttribute("title", tooltip, null);
-            // render Value
-            control.renderValue(valInfo, writer);
-            writer.endElement(this.tagName);
+            control.renderValue(this, this.tagName, styleClass, tooltip, 
valInfo, context);
         }
     }
 
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
index 8ee076d..acb1cc6 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
@@ -20,7 +20,6 @@ package org.apache.empire.jsf2.components;
 
 import java.io.IOException;
 import java.util.List;
-import java.util.Map;
 
 import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
@@ -28,7 +27,6 @@ import javax.faces.component.UIInput;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
 import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
 import javax.faces.convert.ConverterException;
 import javax.faces.view.AttachedObjectHandler;
 
@@ -196,10 +194,10 @@ public class InputTag extends UIInput implements 
NamingContainer
         // render components
         if (readOnly)
         {   // render value
-            ResponseWriter writer = context.getResponseWriter();
-            String tag = writeStartElement(inpInfo, writer);
-            control.renderValue(inpInfo, writer);
-            writer.endElement(tag);
+            String tagName = "span";
+            String styleClass = helper.getTagStyleClass("eInpDis");
+            String tooltip = 
helper.getValueTooltip(helper.getTagAttributeValue("title"));
+            control.renderValue(this, tagName, styleClass, tooltip, inpInfo, 
context);
         }
         else
         {   // render input
@@ -378,32 +376,6 @@ public class InputTag extends UIInput implements 
NamingContainer
         // partial  
         return helper.isPartialSubmit(context);
     }
-
-    /**
-     * write value element
-     * 
-     * @param vi
-     * @param writer
-     * @return
-     * @throws IOException
-     */
-    protected String writeStartElement(InputControl.ValueInfo vi, 
ResponseWriter writer)
-        throws IOException
-    {
-        // tag and class name
-        String tagName = "span";
-        String className = helper.getTagStyleClass("eInpDis");
-        // other attributes
-        Map<String, Object> map = getAttributes();
-        Object style = map.get("style");
-        Object title = map.get("title");
-        // Write tag
-        writer.startElement(tagName, this);
-        helper.writeAttribute(writer, "class", className);
-        helper.writeAttribute(writer, "style", style);
-        helper.writeAttribute(writer, "title", helper.getValueTooltip(title));
-        return tagName;
-    }
     
     protected void attachEvents(FacesContext context)
     {
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java
index 762a33f..5b6473f 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ValueTag.java
@@ -60,47 +60,41 @@ public class ValueTag extends UIOutput // implements 
NamingContainer
         super.encodeBegin(context);
         
         helper.encodeBegin();
-        InputControl control = helper.getInputControl();
-        InputControl.ValueInfo vi = helper.getValueInfo(context);
 
         // render components
-        ResponseWriter writer = context.getResponseWriter();
-        String tag = writeStartElement(vi, writer);
-        control.renderValue(vi, writer);
-        if (tag != null)
-            writer.endElement(tag);
+        InputControl control = helper.getInputControl();
+        InputControl.ValueInfo vi = helper.getValueInfo(context);
+        renderControlValue(control, vi, context);
     }
 
-    protected String writeStartElement(InputControl.ValueInfo vi, 
ResponseWriter writer)
+    protected void renderControlValue(InputControl control, 
InputControl.ValueInfo vi, FacesContext context)
         throws IOException
     {
         // Map<String, Object> map = getAttributes();
-        String tag   = helper.getTagAttributeString("tag");
-        Object title = helper.getTagAttributeValue("title");
+        String tagName = helper.getTagAttributeString("tag");
+        String tooltip = helper.getTagAttributeString("title");
+        String styleClass = helper.getTagAttributeString("styleClass");
         // Check
-        if (tag == null && title == null && 
helper.getTagAttributeValue("styleClass")==null)
-            return null;
-        // Write tag
-        if (StringUtils.isEmpty(tag))
-            tag="span";
-        writer.startElement(tag, this);
-        // Detect type and additional style
-        String addlStyle = null;
-        DataType dataType = vi.getColumn().getDataType();
-        if (dataType.isNumeric())
-        {   try {
-                Object val = helper.getDataValue(true);
-                if (val!=null && ObjectUtils.getLong(val)<0)
-                    addlStyle = "eValNeg";
-            } catch(Exception e) {
-                log.warn("Unable to detect sign of numeric value {}. Message 
is {}!", vi.getColumn().getName(), e.getMessage());
+        if (StringUtils.isNotEmpty(tagName) || 
StringUtils.isNotEmpty(styleClass) || StringUtils.isNotEmpty(tooltip))
+        {   // tagname
+            if (StringUtils.isEmpty(tagName))
+                tagName="span";
+            // Detect type and additional style
+            String addlStyle = null;
+            DataType dataType = vi.getColumn().getDataType();
+            if (dataType.isNumeric())
+            {   try {
+                    Object val = helper.getDataValue(true);
+                    if (val!=null && ObjectUtils.getLong(val)<0)
+                        addlStyle = "eValNeg";
+                } catch(Exception e) {
+                    log.warn("Unable to detect sign of numeric value {}. 
Message is {}!", vi.getColumn().getName(), e.getMessage());
+                }
             }
+            styleClass = helper.getTagStyleClass(dataType, addlStyle);
         }
-        // render attributes
-        helper.writeAttribute(writer, "class", 
helper.getTagStyleClass(dataType, addlStyle));
-        helper.writeAttribute(writer, "style", 
helper.getTagAttributeString("style"));
-        helper.writeAttribute(writer, "title", helper.getValueTooltip(title));
-        return tag;
+        // render now
+        control.renderValue(this, tagName, styleClass, tooltip, vi, context);
     }
 
 }
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
index 2d1e7a3..75d0646 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
@@ -210,7 +210,49 @@ public abstract class InputControl
         }
     }
     
-    /* Value */
+    /**
+     * Renders the control value with a surrounding HTML tag, if a tagName is 
supplied
+     * @param comp the JSF component
+     * @param tagName the tag name of the HTML wrapper tag (optional)
+     * @param styleClass the style class of the HTML wrapper tag (optional)
+     * @param tooltip the title of the HTML wrapper tag (optional)
+     * @param vi the value info
+     * @param context the FacesContext
+     * @throws IOException
+     */
+    public void renderValue(UIComponent comp, String tagName, String 
styleClass, String tooltip, ValueInfo vi, FacesContext context)
+        throws IOException
+    {
+        // writer
+        ResponseWriter writer = context.getResponseWriter();
+        // has tag?
+        if (tagName!=null)
+        {   // write start tag
+            writer.startElement(tagName, comp);
+            if (StringUtils.isNotEmpty(styleClass))
+                writer.writeAttribute("class", styleClass, null);
+            if (StringUtils.isNotEmpty(tooltip))
+                writer.writeAttribute("title", tooltip, null);
+            // style
+            Object style = comp.getAttributes().get("style");
+            if (style!=null)
+                writer.writeAttribute("style", style, null);
+        }
+        // render Value
+        renderValue(vi, writer);
+        // has tag?
+        if (tagName!=null)
+        {   // write end tag
+            writer.endElement(tagName);
+        }
+    }
+    
+    /**
+     * Renders the control value without a surrounding tag (Text only)
+     * @param vi the value info
+     * @param writer the output writer
+     * @throws IOException
+     */
     public void renderValue(ValueInfo vi, ResponseWriter writer)
         throws IOException
     {
@@ -218,7 +260,13 @@ public abstract class InputControl
         writer.append((StringUtils.isEmpty(text) ? HTML_EXPR_NBSP : text));
     }
 
-    /* renderInput */ 
+    /**
+     * Renders the input element(s) for editing the underlying record value 
+     * @param comp the JSF component
+     * @param ii the input info
+     * @param context the FacesContext
+     * @throws IOException
+     */
     public void renderInput(UIComponent comp, InputInfo ii, FacesContext 
context)
         throws IOException
     {

Reply via email to