empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1375658 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: app/FacesApplication.java components/ControlTag.java components/InputTag.java
Date Tue, 21 Aug 2012 16:48:59 GMT
Author: doebele
Date: Tue Aug 21 16:48:59 2012
New Revision: 1375658

URL: http://svn.apache.org/viewvc?rev=1375658&view=rev
Log:
EMPIREDB-162
Allows partial submit (ignore Input controls that have been manually set to "not required")

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.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

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java?rev=1375658&r1=1375657&r2=1375658&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/FacesApplication.java
Tue Aug 21 16:48:59 2012
@@ -35,6 +35,7 @@ import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
 import javax.sql.DataSource;
 
+import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.DataType;
 import org.apache.empire.db.DBDatabase;
@@ -151,6 +152,28 @@ public abstract class FacesApplication e
         }
         return false;
     }
+    
+    /**
+     * returns true if a form input element has been partially submitted
+     * @param fc the Faces Context
+     * @return the componentId or null if no partial submit was been performed
+     */
+    public boolean isPartialSubmit(final FacesContext fc)
+    {
+        Map<String,String> parameterMap = fc.getExternalContext().getRequestParameterMap();
   
+        return ObjectUtils.getBoolean(parameterMap.get("ice.submit.partial"));      
+    }
+
+    /**
+     * returns the componentId for which a partial submit has been performed.
+     * @param fc the Faces Context
+     * @return the componentId or null if no partial submit was been performed
+     */
+    public String getPartialSubmitComponentId(final FacesContext fc)
+    {
+        Map<String,String> parameterMap = fc.getExternalContext().getRequestParameterMap();
+        return parameterMap.get("ice.event.captured"); 
+    }
 
     /**
      * finds a component from with a given id from a given start component

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=1375658&r1=1375657&r2=1375658&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
Tue Aug 21 16:48:59 2012
@@ -205,6 +205,7 @@ public class ControlTag extends UIInput 
 
     protected InputControl control = null;
     protected InputControl.InputInfo inpInfo = null;
+    protected boolean hasRequiredFlagSet = false;
 
     public ControlTag()
     {
@@ -330,6 +331,14 @@ public class ControlTag extends UIInput 
     {
         super.encodeEnd(context);
     }
+
+    @Override
+    public void setRequired(boolean required) 
+    {
+        super.setRequired(required);
+        // flag has been set
+        hasRequiredFlagSet = true;
+    }
     
     private boolean isCustomInput()
     {
@@ -376,8 +385,12 @@ public class ControlTag extends UIInput 
         else
         {
             inpInfo = helper.getInputInfo(context);
+            // set required
+            if (hasRequiredFlagSet==false)
+                super.setRequired(helper.isValueRequired());
             // render input
             control.renderInput(parent, inpInfo, context, false);
+            
         }
         // render components
         parent.encodeAll(context);
@@ -410,8 +423,14 @@ public class ControlTag extends UIInput 
     @Override
     public void validateValue(FacesContext context, Object value)
     {   // Check state
-        if (inpInfo==null)
+        if (inpInfo==null || !isValid())
             return;
+        // Skip Null values if not required
+        if (hasRequiredFlagSet && !isRequired() && isEmpty(value)) //  &&
helper.isValueRequired()
+        {   // Value is null, but not required
+            log.debug("Skipping validation for {} due to Null value.", inpInfo.getColumn().getName());
+            return;
+        }
         // Validate value
         inpInfo.validate(value);
         setValid(true);
@@ -453,9 +472,17 @@ public class ControlTag extends UIInput 
         // No Action
         if (!isValid() || !isLocalValueSet())
             return; 
+        // check required?
+        Object value = getLocalValue();
+        // check required
+        if (hasRequiredFlagSet && !isRequired() && isEmpty(value) &&
helper.isValueRequired())
+        {   // Value is null, but not required
+            log.debug("Skipping model update for {} due to Null value.", inpInfo.getColumn().getName());
+            return;
+        }
         // super.updateModel(context);
         log.debug("Updating model input for {}.", inpInfo.getColumn().getName());
-        inpInfo.setValue(getLocalValue());
+        inpInfo.setValue(value);
         setValue(null);
         setLocalValueSet(false);
         // Post update

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=1375658&r1=1375657&r2=1375658&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
Tue Aug 21 16:48:59 2012
@@ -45,6 +45,7 @@ public class InputTag extends UIInput im
 
     private InputControl control = null;
     private InputControl.InputInfo inpInfo = null;
+    protected boolean hasRequiredFlagSet = false;
 
     private static int itemIdSeq = 0;
     private final int itemId;
@@ -113,6 +114,9 @@ public class InputTag extends UIInput im
         else
         {
             inpInfo = helper.getInputInfo(context);
+            // set required
+            if (hasRequiredFlagSet==false)
+                super.setRequired(helper.isValueRequired());
             // render input
             control.renderInput(this, inpInfo, context, true);
         }
@@ -120,6 +124,14 @@ public class InputTag extends UIInput im
     }
 
     @Override
+    public void setRequired(boolean required) 
+    {
+        super.setRequired(required);
+        // flag has been set
+        hasRequiredFlagSet = true;
+    }
+
+    @Override
     public Object getValue()
     {
         // check for record
@@ -144,6 +156,12 @@ public class InputTag extends UIInput im
     {   // Check state
         if (inpInfo==null)
             return;
+        // Skip Null values if not required
+        if (hasRequiredFlagSet && !isRequired() && isEmpty(value)) //  &&
helper.isValueRequired()
+        {   // Value is null, but not required
+            log.debug("Skipping validation for {} due to Null value.", inpInfo.getColumn().getName());
+            return;
+        }
         // Validate value
         inpInfo.validate(value);
         setValid(true);
@@ -186,9 +204,16 @@ public class InputTag extends UIInput im
         // No Action
         if (!isValid() || !isLocalValueSet())
             return; 
+        // check required
+        Object value = getLocalValue();
+        if (hasRequiredFlagSet && !isRequired() && isEmpty(value) &&
helper.isValueRequired())
+        {   // Value is null, but not required
+            log.debug("Skipping model update for {} due to Null value.", inpInfo.getColumn().getName());
+            return;
+        }
         // super.updateModel(context);
         log.debug("Updating model input for {}.", inpInfo.getColumn().getName());
-        inpInfo.setValue(getLocalValue());
+        inpInfo.setValue(value);
         setValue(null);
         setLocalValueSet(false);
         // Post update



Mime
View raw message