You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2020/01/13 21:50:31 UTC

[empire-db] branch master updated: EMPIREDB-320 yet another improvement for Input control decoding and validation

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 c111666  EMPIREDB-320 yet another improvement for Input control decoding and validation
c111666 is described below

commit c1116669ff5ba123ebd6b3a6e3768a9c73ddba59
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Mon Jan 13 22:50:27 2020 +0100

    EMPIREDB-320
    yet another improvement for Input control decoding and validation
---
 .../apache/empire/jsf2/components/ControlTag.java  | 80 +++++++++++++---------
 .../apache/empire/jsf2/components/InputTag.java    | 42 +++++++-----
 2 files changed, 73 insertions(+), 49 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 04a6d54..e42c39c 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
@@ -545,9 +545,15 @@ public class ControlTag extends UIInput implements NamingContainer
     @Override
     public void processDecodes(FacesContext context) 
     {
-        /*
-         * previous code moved to processValidators (below)
-         */
+        // check UI-Data
+        if (helper.isInsideUIData() && getChildCount()>0)
+        {   // update input state
+            updateControlInputState(context);
+            // render Input or Value component
+            boolean readOnly = helper.isRecordReadOnly();
+            setRenderInput(!readOnly);
+        }
+        // default
         super.processDecodes(context);
     }
 
@@ -555,34 +561,9 @@ public class ControlTag extends UIInput implements NamingContainer
     public void processValidators(FacesContext context)
     {
         // check UI-Data
-        if (helper.isInsideUIData())
-        {   // Check input controls
-            if (getChildCount()>1 && (getChildren().get(1) instanceof InputSeparatorComponent))
-            {   // Make sure all inputs are rendered
-                boolean hasChanged = false;
-                boolean readOnly = helper.isRecordReadOnly();
-                InputSeparatorComponent parent = (InputSeparatorComponent)getChildren().get(1);
-                // set rendered of children
-                for (UIComponent child : parent.getChildren())
-                {   // set rendered 
-                    boolean rendered = (child instanceof ValueOutputComponent) ? readOnly : !readOnly;
-                    if (child.isRendered()!=rendered)
-                    {   child.setRendered(rendered);
-                        hasChanged = true;
-                    }    
-                }
-                // give control chance to update
-                if (hasChanged && log.isDebugEnabled())
-                    log.debug("Changing UIInput readOnly state for {} to {}", helper.getColumnName(), readOnly);
-                // check record
-                helper.prepareData();
-                if (this.control==null)
-                    this.control = helper.getInputControl();
-                if (this.inpInfo==null)
-                    this.inpInfo = helper.getInputInfo(context);
-                // update state
-                this.control.updateInputState(parent, inpInfo, context, false);
-            }
+        if (helper.isInsideUIData() && getChildCount()>0)
+        {   // update input state
+            updateControlInputState(context);
         }
         // process all validators (including children)
         super.processValidators(context);
@@ -675,6 +656,43 @@ public class ControlTag extends UIInput implements NamingContainer
         return helper.isValueRequired();
     }
     
+    protected void updateControlInputState(FacesContext context)
+    {
+        // get control
+        helper.prepareData();
+        if (control==null)
+            control = helper.getInputControl();
+        if (inpInfo==null)
+            inpInfo = helper.getInputInfo(context);
+        // update control
+        control.updateInputState(this, inpInfo, context, false);
+    }
+
+    protected void setRenderInput(boolean renderInput)
+    {
+        if (getChildCount()>1 && (getChildren().get(1) instanceof InputSeparatorComponent))
+        {   // Make sure all inputs are rendered
+            boolean hasChanged = false;
+            InputSeparatorComponent parent = (InputSeparatorComponent)getChildren().get(1);
+            // set rendered of children
+            for (UIComponent child : parent.getChildren())
+            {   // set rendered 
+                boolean rendered = (child instanceof ValueOutputComponent) ? renderInput : !renderInput;
+                if (child.isRendered()!=rendered)
+                {   child.setRendered(rendered);
+                    hasChanged = true;
+                }    
+            }
+            // give control chance to update
+            if (hasChanged && log.isDebugEnabled())
+                log.debug("Changing UIInput readOnly state for {} to {}", helper.getColumnName(), renderInput);
+        }
+        else
+        {   // Must have at least two children, one for Input and one for Output
+            log.warn("Control-Tag does not have separate Input and Output components");
+        }
+    }
+    
     protected boolean getColon()
     {
         Object colon = getAttributes().get("colon");
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 5cf4a8e..7736b92 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
@@ -262,9 +262,15 @@ public class InputTag extends UIInput implements NamingContainer
     @Override
     public void processDecodes(FacesContext context) 
     {
-        /*
-         * previous code moved to processValidators (below)
-         */
+        // check UI-Data
+        if (helper.isInsideUIData() && getChildCount()>0)
+        {   // update input state
+            updateControlInputState(context);
+            // Set readOnly and disabled for each row
+            boolean readOnly = helper.isRecordReadOnly();
+            setRenderInput(!readOnly);
+        }
+        // default
         super.processDecodes(context);
     }
 
@@ -272,21 +278,9 @@ public class InputTag extends UIInput implements NamingContainer
     public void processValidators(FacesContext context)
     {
         // check UI-Data
-        if (helper.isInsideUIData())
-        {   // Check input controls
-            if (getChildCount()>0)
-            {   // Set readOnly and disabled for each row
-                boolean readOnly = helper.isRecordReadOnly();
-                setRenderInput(!readOnly);
-                // get control
-                helper.prepareData();
-                if (control==null)
-                    control = helper.getInputControl();
-                if (inpInfo==null)
-                    inpInfo = helper.getInputInfo(context);
-                // update control
-                control.updateInputState(this, inpInfo, context, false);
-            }
+        if (helper.isInsideUIData() && getChildCount()>0)
+        {   // update input state
+            updateControlInputState(context);
         }
         // process all validators (including children)
         super.processValidators(context);
@@ -372,6 +366,18 @@ public class InputTag extends UIInput implements NamingContainer
     {
         return helper.isValueRequired();
     }
+    
+    protected void updateControlInputState(FacesContext context)
+    {
+        // get control
+        helper.prepareData();
+        if (control==null)
+            control = helper.getInputControl();
+        if (inpInfo==null)
+            inpInfo = helper.getInputInfo(context);
+        // update control
+        control.updateInputState(this, inpInfo, context, false);
+    }
 
     protected void setRenderInput(boolean renderInput)
     {