empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1375437 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: app/ components/ controls/ utils/
Date Tue, 21 Aug 2012 09:14:38 GMT
Author: doebele
Date: Tue Aug 21 09:14:37 2012
New Revision: 1375437

URL: http://svn.apache.org/viewvc?rev=1375437&view=rev
Log:
EMPIREDB-160
For JSF2 with Morjarra 2.1.6: Preserve submitted values over the request phase (works for
Empire Input Controls only!)

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/components/MenuItemTag.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.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=1375437&r1=1375436&r2=1375437&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
Tue Aug 21 09:14:37 2012
@@ -32,6 +32,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;
@@ -237,4 +238,15 @@ public class FacesUtils
         addErrorMessage(fc, null, msg);
     }
     
+    public static boolean isClearSubmittedValues(FacesContext fc)
+    {
+        Object validate = fc.getExternalContext().getRequestMap().get("CLEAR_SUBMITTED_VALUES");
+        return (validate!=null ? ObjectUtils.getBoolean(validate) : false);
+    }
+
+    public static void setClearSubmittedValues(FacesContext fc, boolean validate)
+    {
+        fc.getExternalContext().getRequestMap().put("CLEAR_SUBMITTED_VALUES", validate);
+    }
+    
 }

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=1375437&r1=1375436&r2=1375437&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 09:14:37 2012
@@ -169,10 +169,15 @@ public class ControlTag extends UIInput 
             }
             
             ControlTag controlTag = (ControlTag)parent;
-            TagEncodingHelper helper = controlTag.helper;
+            InputControl control = controlTag.control;
+            InputControl.ValueInfo valInfo = controlTag.inpInfo;
 
-            InputControl control = helper.getInputControl();
-            InputControl.ValueInfo valInfo = helper.getValueInfo(context);
+            TagEncodingHelper helper = controlTag.helper;
+            if (control==null)
+                control = helper.getInputControl(); // Oops, should not come here 
+            if (valInfo==null)
+                valInfo = helper.getValueInfo(context); // Oops, should not come here 
+            
             String styleClass = helper.getTagStyleClass("eInpDis");
             String tooltip    = helper.getValueTooltip(helper.getTagAttribute("title"));
             
@@ -397,8 +402,8 @@ public class ControlTag extends UIInput 
         // Get Input Tag
         if (getChildCount()<=1)
             return null;
-        ControlSeparatorComponent inputSepTag = (ControlSeparatorComponent) getChildren().get(1);

         // get Input Value
+        ControlSeparatorComponent inputSepTag = (ControlSeparatorComponent) getChildren().get(1);

         return control.getInputValue(inputSepTag, inpInfo, true);
     }
 
@@ -425,7 +430,6 @@ public class ControlTag extends UIInput 
         // get submitted value and validate
         if (log.isDebugEnabled())
             log.debug("Validating input for {}.", inpInfo.getColumn().getName());
-        
         // Validate value
         try {
             // Will internally call getSubmittedValue() and validateValue() 
@@ -454,6 +458,9 @@ public class ControlTag extends UIInput 
         inpInfo.setValue(getLocalValue());
         setValue(null);
         setLocalValueSet(false);
+        // Post update
+        ControlSeparatorComponent inputSepTag = (ControlSeparatorComponent) getChildren().get(1);

+        control.postUpdateModel(inputSepTag, inpInfo, context);
     }
     
     public Column getInputColumn()

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=1375437&r1=1375436&r2=1375437&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 09:14:37 2012
@@ -191,6 +191,8 @@ public class InputTag extends UIInput im
         inpInfo.setValue(getLocalValue());
         setValue(null);
         setLocalValueSet(false);
+        // Post update
+        control.postUpdateModel(this, inpInfo, context);
     }
     
     public Column getInputColumn()

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuItemTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuItemTag.java?rev=1375437&r1=1375436&r2=1375437&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuItemTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuItemTag.java
Tue Aug 21 09:14:37 2012
@@ -208,29 +208,34 @@ public class MenuItemTag extends LinkTag
     private String getStyleClass()
     {
         String styleClass = StringUtils.toString(getAttributes().get("styleClass"));
-        String menuClass = null; 
         if (parentMenu!=null)
         {
-            // Menu Class
-            if (isCurrent())
-                menuClass = parentMenu.getCurrentClass();
-            else if (isExpanded())
-                menuClass = parentMenu.getExpandedClass();
-            else if (isDisabled())
-                menuClass = parentMenu.getDisabledClass();
-            else
-                menuClass = parentMenu.getEnabledClass();
             // Style Class
             if (StringUtils.isEmpty(styleClass))
                 styleClass = parentMenu.getItemStyleClass();
+            // Menu Class
+            if (isCurrent())
+                styleClass = appendStyleClass(styleClass, parentMenu.getCurrentClass());
+            else if (isExpanded())
+                styleClass = appendStyleClass(styleClass, parentMenu.getExpandedClass());
+            // Disabled / enabled
+            if (isDisabled())
+                styleClass = appendStyleClass(styleClass, parentMenu.getDisabledClass());
+        }
+        else
+        {   // disabled
+            if (isDisabled())
+                styleClass = appendStyleClass(styleClass, "disabled");
         }
-        // check
-        if (menuClass==null)
-            return styleClass;
-        if (StringUtils.isEmpty(styleClass))
-            return menuClass;
         // both supplied
-        return styleClass+" "+menuClass;
+        return styleClass;
+    }
+    
+    private String appendStyleClass(String styleClass, String newClass)
+    {
+        if (StringUtils.isEmpty(newClass))
+            return styleClass;
+        return (styleClass==null) ? newClass : " "+newClass;
     }
     
 }

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java?rev=1375437&r1=1375436&r2=1375437&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/CheckboxInputControl.java
Tue Aug 21 09:14:37 2012
@@ -24,6 +24,7 @@ import javax.faces.component.UIComponent
 import javax.faces.component.html.HtmlSelectBooleanCheckbox;
 import javax.faces.context.FacesContext;
 
+import org.apache.empire.commons.ObjectUtils;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
 
@@ -73,5 +74,17 @@ public class CheckboxInputControl extend
         input.setDisabled(ii.isDisabled());
         setInputValue(input, ii);
     }
-
+    
+    @Override
+    public Object getInputValue(UIComponent comp, InputInfo ii, boolean submitted)
+    {
+        Object value = super.getInputValue(comp, ii, submitted);
+        // Convert to boolean
+        if (!ObjectUtils.isEmpty(value))
+        {
+            return ObjectUtils.getBoolean(value);
+        }
+        return value;
+    }
+    
 }

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java?rev=1375437&r1=1375436&r2=1375437&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
Tue Aug 21 09:14:37 2012
@@ -21,6 +21,7 @@ package org.apache.empire.jsf2.controls;
 import java.io.IOException;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.el.ValueExpression;
 import javax.faces.component.UIComponent;
@@ -34,6 +35,7 @@ import org.apache.empire.commons.StringU
 import org.apache.empire.data.Column;
 import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
+import org.apache.empire.jsf2.app.FacesUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -147,7 +149,7 @@ public abstract class InputControl
     */
     
     private static final Logger log = LoggerFactory.getLogger(InputControl.class);
-
+    
     // Special Input Column Attributes
     public static final String NUMBER_TYPE_ATTRIBUTE      = "numberType";   // "Integer",
"Currency", "Percent"  
     public static final String NUMBER_GROUPSEP_ATTRIBUTE  = "numberGroupSeparator"; // boolean
@@ -210,6 +212,7 @@ public abstract class InputControl
         String getOnfocus();
         String getOnblur();
         */
+        Object getAttribute(String name);
     }
     
     private String name;
@@ -247,6 +250,15 @@ public abstract class InputControl
         }
     }
     
+    public void postUpdateModel(UIComponent comp, InputInfo ii, FacesContext fc)
+    {
+        UIInput input = getInputComponent(comp);
+        if (input==null)
+            return; /* May want to override this */
+        // Clear submitted value
+        clearSubmittedValue(input);
+    }
+    
     public Object getInputValue(UIComponent comp, InputInfo ii, boolean submitted)
     {
         UIInput input = getInputComponent(comp);
@@ -254,18 +266,74 @@ public abstract class InputControl
             throw new ObjectNotValidException(this);
         
         // Get value from Input
-        return (submitted) ? input.getSubmittedValue() : input.getValue();        
+        Object value = (submitted) ? input.getSubmittedValue() : input.getValue();
+        if (submitted && value!=null)
+        {
+            // if (!ObjectUtils.compareEqual(value, input.getLocalValue())
+            // {
+            // }
+            
+            FacesContext fc = FacesContext.getCurrentInstance();
+            Map<String, Object> reqMap = fc.getExternalContext().getRequestMap();
+            // Save submitted value
+            String clientId = input.getClientId();
+            if (reqMap.containsKey(clientId))
+            {
+                log.warn("OOps, what is going on here?");
+            }            
+            reqMap.put(clientId, value);
+        }
+        return value;
     }
 
     protected void setInputValue(UIInput input, InputInfo ii)
     {
+        if (input.isLocalValueSet())
+            return;
+        else
+        {   // check Request Map
+            FacesContext fc = FacesContext.getCurrentInstance();
+            if (FacesUtils.isClearSubmittedValues(fc))
+            {   // Clear submitted value
+                if (input.getSubmittedValue()!=null)
+                    input.setSubmittedValue(null);
+            }
+            else
+            {   // Restore submitted value
+                Map<String, Object> reqMap = fc.getExternalContext().getRequestMap();
+                String clientId = input.getClientId();
+                if (reqMap.containsKey(clientId))
+                {   // Set the local value from the request map
+                    Object value = reqMap.get(clientId);
+                    input.setSubmittedValue(value);
+                    return;
+                }
+            }
+        }
+        
         Object value = ii.getValue(false);
         if (value instanceof ValueExpression)
         {   input.setLocalValueSet(false);
             input.setValueExpression("value", (ValueExpression)value);
+            
+            Object check = ((ValueExpression)value).getValue(FacesContext.getCurrentInstance().getELContext());
+            log.info("Expression value is {}.", check);
         }    
         else
+        {   // Set the value
             input.setValue(value);
+        }    
+    }    
+
+    protected void clearSubmittedValue(UIInput input)
+    {
+        input.setSubmittedValue(null);
+        // check Request Map
+        FacesContext fc = FacesContext.getCurrentInstance();
+        Map<String, Object> reqMap = fc.getExternalContext().getRequestMap();
+        String clientId = input.getClientId();
+        if (reqMap.containsKey(clientId))
+            reqMap.remove(clientId);
     }    
     
     /* validate 

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=1375437&r1=1375436&r2=1375437&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
Tue Aug 21 09:14:37 2012
@@ -301,6 +301,11 @@ public class TagEncodingHelper implement
             return getTagStyleClass(addlStyle);
         }
 
+        @Override
+        public Object getAttribute(String name)
+        {
+            return getTagAttribute(name);
+        }
     }
 
     // Logger
@@ -327,6 +332,43 @@ public class TagEncodingHelper implement
     {
         /* nothing */
     }
+
+    public InputControl getInputControl()
+    {
+        if (control != null)
+        {   // Must check record!
+            checkRecord();
+            return control;
+        }    
+        // Create
+        if (getColumn() == null)
+        	throw new NotSupportedException(this, "getInputControl");
+        // Get Control from column
+        String controlType = column.getControlType();
+        if (StringUtils.isNotEmpty(controlType))
+            control = InputControlManager.getControl(controlType);
+        if (control == null)
+        { // Auto-detect
+            if (getValueOptions()!=null)
+                controlType = SelectInputControl.NAME;
+            else
+            {   // get from data type
+                DataType dataType = column.getDataType();
+                controlType = FacesUtils.getFacesApplication().getDefaultControlType(dataType);
+            }
+            // get default control
+            control = InputControlManager.getControl(controlType);
+            // Still not? Use Text Control
+            if (control == null)
+                control = InputControlManager.getControl(TextInputControl.NAME);
+            // debug
+            if (log.isDebugEnabled() && !controlType.equals(TextInputControl.NAME))
+                log.debug("Auto-detected field control for " + column.getName() + " is "
+ controlType);
+        }
+        // check record
+        checkRecord();
+        return control;
+    }
     
     private void checkRecord()
     {
@@ -364,41 +406,6 @@ public class TagEncodingHelper implement
         }
     }
 
-    public InputControl getInputControl()
-    {
-        if (control != null)
-            return control;
-        // Create
-        if (getColumn() == null)
-        	throw new NotSupportedException(this, "getInputControl");
-        // Get Control from column
-        String controlType = column.getControlType();
-        InputControl control = null;
-        if (StringUtils.isNotEmpty(controlType))
-            control = InputControlManager.getControl(controlType);
-        if (control == null)
-        { // Auto-detect
-            if (getValueOptions()!=null)
-                controlType = SelectInputControl.NAME;
-            else
-            {   // get from data type
-                DataType dataType = column.getDataType();
-                controlType = FacesUtils.getFacesApplication().getDefaultControlType(dataType);
-            }
-            // get default control
-            control = InputControlManager.getControl(controlType);
-            // Still not? Use Text Control
-            if (control == null)
-                control = InputControlManager.getControl(TextInputControl.NAME);
-            // debug
-            if (log.isDebugEnabled() && !controlType.equals(TextInputControl.NAME))
-                log.debug("Auto-detected field control for " + column.getName() + " is "
+ controlType);
-        }
-        // check record
-        checkRecord();
-        return control;
-    }
-
     public InputControl.ValueInfo getValueInfo(FacesContext ctx)
     {
         return new ValueInfoImpl(getColumn(), getTextResolver(ctx));
@@ -917,20 +924,20 @@ public class TagEncodingHelper implement
     protected String getLabelValue(Column column, boolean colon)
     {
         String label = getTagAttribute("label");
-        if (label!=null)
-            return label;
-        // Check for short form    
-        if (hasFormat("short"))
-        {
-            label = StringUtils.toString(column.getAttribute(COLATTR_ABBR_TITLE));
-            if (label==null)
-                log.warn("No Abbreviation available for column {}. Using normal title.",
column.getName());
-        }
-        // Use normal title
         if (label==null)
-            label=column.getTitle();
-        // translate
-        label = getDisplayText(label);
+        {   // Check for short form    
+            if (hasFormat("short"))
+            {
+                label = StringUtils.toString(column.getAttribute(COLATTR_ABBR_TITLE));
+                if (label==null)
+                    log.warn("No Abbreviation available for column {}. Using normal title.",
column.getName());
+            }
+            // Use normal title
+            if (label==null)
+                label=column.getTitle();
+            // translate
+            label = getDisplayText(label);
+        }    
         // handle empty string
         if (StringUtils.isEmpty(label))
             return "";



Mime
View raw message