empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1381125 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: app/FacesUtils.java components/ControlTag.java components/InputTag.java utils/TagEncodingHelper.java
Date Wed, 05 Sep 2012 10:15:28 GMT
Author: doebele
Date: Wed Sep  5 10:15:28 2012
New Revision: 1381125

URL: http://svn.apache.org/viewvc?rev=1381125&view=rev
Log:
EMPIREDB-157 
JSF2 allow to skip input validation for Input and Control Tags

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java?rev=1381125&r1=1381124&r2=1381125&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesUtils.java
Wed Sep  5 10:15:28 2012
@@ -33,6 +33,7 @@ import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.jsf2.pages.Page;
 import org.apache.empire.jsf2.pages.PageDefinition;
@@ -45,6 +46,8 @@ public class FacesUtils
 {
 
     private static final Logger log = LoggerFactory.getLogger(FacesUtils.class);
+    
+    public static final String SKIP_INPUT_VALIDATION_PARAM = "empire.jsf.input.skipValidation";
 
     /* App */
 
@@ -281,5 +284,12 @@ public class FacesUtils
         fc.getExternalContext().getRequestMap().put("CLEAR_SUBMITTED_VALUES", validate);
     }
     */
+
+    public static boolean isSkipInputValidation(final FacesContext fc)
+    {
+        // Skip validate
+        String val = FacesUtils.getRequestParam(fc, SKIP_INPUT_VALIDATION_PARAM);
+        return (val!=null && ObjectUtils.getBoolean(val));
+    }
     
 }

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java?rev=1381125&r1=1381124&r2=1381125&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
Wed Sep  5 10:15:28 2012
@@ -448,8 +448,8 @@ public class ControlTag extends UIInput 
         // Validate value
         inpInfo.validate(value);
         setValid(true);
-        // call base class 
-        super.validateValue(context, value);
+        // don't call base class!
+        // super.validateValue(context, value);
     }    
     
     @Override

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java?rev=1381125&r1=1381124&r2=1381125&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
Wed Sep  5 10:15:28 2012
@@ -176,8 +176,8 @@ public class InputTag extends UIInput im
         // Validate value
         inpInfo.validate(value);
         setValid(true);
-        // call base class 
-        super.validateValue(context, value);
+        // don't call base class!
+        // super.validateValue(context, value);
     }    
     
     @Override

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java?rev=1381125&r1=1381124&r2=1381125&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
Wed Sep  5 10:15:28 2012
@@ -272,6 +272,9 @@ public class TagEncodingHelper implement
         @Override
         public void validate(Object value)
         {
+            // skip?
+            if (skipValidation)
+                return;
             // Make sure null values are not forced to be required
             boolean isNull = ObjectUtils.isEmpty(value);
             if (isNull)
@@ -341,6 +344,7 @@ public class TagEncodingHelper implement
     private InputControl        control      = null;
     private TextResolver        textResolver = null;
     private Object              mostRecentValue = null;
+    private boolean             skipValidation = false;
 
     public TagEncodingHelper(UIOutput tag, String tagCssStyle)
     {
@@ -365,7 +369,7 @@ public class TagEncodingHelper implement
             {   Object req = ve.getValue(FacesContext.getCurrentInstance().getELContext());
                 if (req!=null)
                     tagRequired = new Boolean(ObjectUtils.getBoolean(req));
-            }    
+            }
         }
     }
 
@@ -459,9 +463,17 @@ public class TagEncodingHelper implement
 
     public InputControl.InputInfo getInputInfo(FacesContext ctx)
     {
+        // Skip validate
+        skipValidation = FacesUtils.isSkipInputValidation(ctx);
+        // create
         return new InputInfoImpl(getColumn(), getTextResolver(ctx));
     }
 
+    public boolean isSkipValidation()
+    {
+        return skipValidation;
+    }
+
     public boolean hasColumn()
     {
         if (column == null)
@@ -516,7 +528,7 @@ public class TagEncodingHelper implement
         }
         return null;
     }
-    
+
     private boolean isDetectFieldChange()
     {
         Object v = this.getTagAttribute("detectFieldChange");
@@ -561,9 +573,10 @@ public class TagEncodingHelper implement
     public void setDataValue(Object value)
     {
         if (getRecord() != null)
-        { // value
+        {   // value
             if (record instanceof Record)
-            {   /* special case
+            {   getColumn();
+                /* special case
                 if (value==null && getColumn().isRequired())
                 {   // ((Record)record).isFieldRequired(column)==false
                     log.warn("Unable to set null for required field!");
@@ -572,16 +585,39 @@ public class TagEncodingHelper implement
                 */
                 if (isDetectFieldChange())
                 {   // DetectFieldChange by comparing current and most recent value
-                    Object currentValue = ((Record) record).getValue(getColumn());
+                    Object currentValue = ((Record) record).getValue(column);
                     if (!ObjectUtils.compareEqual(currentValue, mostRecentValue))
                     {   // Value has been changed by someone else!
-                        log.info("Concurrent data change for "+getColumn().getName()+". Current
Value is {}. Ignoring new value {}", currentValue, value);
+                        log.info("Concurrent data change for "+column.getName()+". Current
Value is {}. Ignoring new value {}", currentValue, value);
                         return;
                     }
                 }
-                // a record
-                ((Record) record).setValue(getColumn(), value);
-                mostRecentValue = value;
+                // check whether to skip validation
+                boolean reenableValidation = false;
+                if (skipValidation && (record instanceof DBRecord))
+                {   // Ignore read only values
+                    if (this.isReadOnly())
+                        return;
+                    // Column required?
+                    if (column.isRequired() && ObjectUtils.isEmpty(value))
+                        return; // Cannot set required value to null
+                    // Disable Validation
+                    reenableValidation = ((DBRecord)record).isValidateFieldValues();
+                    if (reenableValidation)
+                        ((DBRecord)record).setValidateFieldValues(false);
+                    // Validation skipped for
+                    if (log.isDebugEnabled())
+                        log.debug("Input Validation skipped for {}.", column.getName());
+                }
+                // Now, set the value
+                try {
+                    ((Record) record).setValue(column, value);
+                    mostRecentValue = value;
+                } finally {
+                    // re-enable validation
+                    if (reenableValidation)
+                        ((DBRecord)record).setValidateFieldValues(true);
+                }
             }
             else if (record instanceof RecordData)
             { // a record



Mime
View raw message