empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1382062 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: components/ controls/ utils/
Date Fri, 07 Sep 2012 15:13:13 GMT
Author: doebele
Date: Fri Sep  7 15:13:12 2012
New Revision: 1382062

URL: http://svn.apache.org/viewvc?rev=1382062&view=rev
Log:
EMPIREDB-157 
JSF2 add or remove disabled style for input controls

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.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/controls/SelectInputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.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/components/SelectTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java?rev=1382062&r1=1382061&r2=1382062&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/SelectTag.java
Fri Sep  7 15:13:12 2012
@@ -179,6 +179,7 @@ public class SelectTag extends UIInput i
         // disabled
         boolean disabled = isDisabled();
         input.setDisabled(disabled);
+        control.addRemoveDisabledStyle(input, disabled);
         // input.setLabel(getLabelString());
         // input.setRequired(col.isRequired() && !col.isAutoGenerated());
         // input.setId(this.getId() + INPUT_SUFFIX);

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=1382062&r1=1382061&r2=1382062&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
Fri Sep  7 15:13:12 2012
@@ -71,9 +71,11 @@ public class CheckboxInputControl extend
         }
 
         // disabled
-        Object dis = ii.getAttributeEx("disabled");
-        boolean disabled = (dis!=null) ? ObjectUtils.getBoolean(dis) : ii.isDisabled(); 
+        boolean disabled = ii.isDisabled(); 
         input.setDisabled(disabled);
+
+        // style
+        addRemoveDisabledStyle(input, input.isDisabled());
         
         // Set Value
         setInputValue(input, ii);

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=1382062&r1=1382061&r2=1382062&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
Fri Sep  7 15:13:12 2012
@@ -33,7 +33,6 @@ import org.apache.empire.commons.ObjectU
 import org.apache.empire.commons.Options;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.Column;
-import org.apache.empire.db.exceptions.FieldIsReadOnlyException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
@@ -202,7 +201,8 @@ public abstract class InputControl
         void setValue(Object value);
         void validate(Object value);
         boolean isRequired();
-        boolean isDisabled(); // readOnly
+        boolean isDisabled(); // disabled or readOnly
+        boolean isFieldReadOnly(); // not disabled only readOnly (for input[type=text] only!)
         // input
         String getInputId();
         String getStyleClass(String addlStyle);
@@ -277,9 +277,11 @@ public abstract class InputControl
             {
                 // Disabled
                 if (ii.isDisabled())
-                {
+                {   // Ignore submitted value
+                    log.debug("Ignoring submitted value for disabled field {}.", ii.getColumn().getName());
                     input.setSubmittedValue(null);
-                    throw new FieldIsReadOnlyException(ii.getColumn());
+                    // throw new FieldIsReadOnlyException(ii.getColumn());
+                    return null;
                 }    
                 // Save submitted value
                 FacesContext fc = FacesContext.getCurrentInstance();
@@ -487,6 +489,24 @@ public abstract class InputControl
             input.getAttributes().put(name, value);
     }
     
+    public void addRemoveDisabledStyle(UIInput input, boolean disabled)
+    {
+        String styleClass = StringUtils.toString(input.getAttributes().get("styleClass"),
"");
+        boolean hasDisStyle = (styleClass.indexOf("eInpDis")>=0);
+        if (disabled==hasDisStyle)
+            return; // Nothing to do
+        // Special IceFaces patch
+        if (styleClass.endsWith("-dis"))
+            styleClass = styleClass.substring(0, styleClass.length()-4);
+        // add or remove disabled style
+        if (disabled)
+            styleClass += " eInpDis";
+        else
+            styleClass = styleClass.replace(" eInpDis", "");
+        // add Style
+        input.getAttributes().put("styleClass", styleClass);
+    }
+    
     /**
      * Returns the value formated as a string
      * this is a simple default implementation that does no type-secific formatting

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java?rev=1382062&r1=1382061&r2=1382062&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/SelectInputControl.java
Fri Sep  7 15:13:12 2012
@@ -84,8 +84,7 @@ public class SelectInputControl extends 
             // copy Attributes
             copyAttributes(parent, ii, input);
             // disabled
-            Object dis = ii.getAttributeEx("disabled");
-            boolean disabled = (dis!=null) ? ObjectUtils.getBoolean(dis) : ii.isDisabled();

+            boolean disabled = ii.isDisabled(); 
             input.setDisabled(disabled);
             // Options
             Options options = ii.getOptions();
@@ -103,9 +102,7 @@ public class SelectInputControl extends 
             // cast
             input = (HtmlSelectOneMenu)comp;
             // disabled
-            // boolean disabled = input.isDisabled();
-            Object dis = ii.getAttributeEx("disabled");
-            boolean disabled = (dis!=null) ? ObjectUtils.getBoolean(dis) : ii.isDisabled();

+            boolean disabled = ii.isDisabled(); 
             input.setDisabled(disabled);
             // Options (sync)
             Options options = ii.getOptions();
@@ -113,6 +110,9 @@ public class SelectInputControl extends 
             String nullText = (hasEmpty) ? getNullText(ii) : "";
             syncOptions(input, ii.getTextResolver(), options, hasEmpty, nullText);
         }
+
+        // style
+        addRemoveDisabledStyle(input, input.isDisabled());
         
         // Set Value
         setInputValue(input, ii);

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java?rev=1382062&r1=1382061&r2=1382062&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextAreaInputControl.java
Fri Sep  7 15:13:12 2012
@@ -68,10 +68,6 @@ public class TextAreaInputControl extend
             }
             // once
             copyAttributes(parent, ii, input);
-            // disabled
-            Object dis = ii.getAttributeEx("disabled");
-            if (dis!=null)
-                input.setDisabled(ObjectUtils.getBoolean(dis));
             // cols
             int cols = getFormatInteger(ii, FORMAT_COLS, FORMAT_COLS_ATTRIBUTE);
             if (cols>0)
@@ -91,9 +87,18 @@ public class TextAreaInputControl extend
             // cast
             input = (HtmlInputTextarea)comp;
         }
+
+        // disabled
+        Object dis = ii.getAttributeEx("disabled");
+        if (dis!=null)
+            input.setDisabled(ObjectUtils.getBoolean(dis));
+        // field-readOnly
+        if (ObjectUtils.getBoolean(dis)==false)
+            input.setReadonly(ii.isFieldReadOnly());
+        // style
+        addRemoveDisabledStyle(input, (input.isDisabled() || input.isReadonly()));
         
         // Set Value
-        input.setReadonly(ii.isDisabled());
         setInputValue(input, ii);
         
     }

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java?rev=1382062&r1=1382061&r2=1382062&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/TextInputControl.java
Fri Sep  7 15:13:12 2012
@@ -87,10 +87,6 @@ public class TextInputControl extends In
             }
             // once
             copyAttributes(parent, ii, input);
-            // disabled
-            Object dis = ii.getAttributeEx("disabled");
-            if (dis!=null)
-                input.setDisabled(ObjectUtils.getBoolean(dis));
             // language
             input.setLang(ii.getLocale().getLanguage());
             // maxlength
@@ -121,11 +117,19 @@ public class TextInputControl extends In
             // cast
             input = (HtmlInputText)comp;
         }
-            
-        // Set Value
-        input.setReadonly(ii.isDisabled()); //  || ii.getColumn().isAutoGenerated()
-        setInputValue(input, ii);
+
+        // disabled
+        Object dis = ii.getAttributeEx("disabled");
+        if (dis!=null)
+            input.setDisabled(ObjectUtils.getBoolean(dis));
+        // field-readOnly
+        if (ObjectUtils.getBoolean(dis)==false)
+            input.setReadonly(ii.isFieldReadOnly());
+        // style
+        addRemoveDisabledStyle(input, (input.isDisabled() || input.isReadonly()));
         
+        // set value
+        setInputValue(input, ii);
     }
     
     // ------- parsing -------

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=1382062&r1=1382061&r2=1382062&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
Fri Sep  7 15:13:12 2012
@@ -301,6 +301,21 @@ public class TagEncodingHelper implement
         }
 
         @Override
+        public boolean isFieldReadOnly()
+        {   // Check Record
+            if (isRecordReadOnly())
+                return true;
+            // Check Record
+            if ((getRecord() instanceof Record))
+            { // Ask Record
+                Record r = (Record) record;
+                return r.isFieldReadOnly(getColumn());
+            }
+            // column
+            return getColumn().isReadOnly();
+        }
+        
+        @Override
         public String getInputId()
         {
             Column c = getColumn();
@@ -311,8 +326,8 @@ public class TagEncodingHelper implement
         public String getStyleClass(String addlStyle)
         {
             String style = getTagStyleClass(addlStyle);
-            if (isReadOnly())
-                style += " eInpDis";
+            // if (isReadOnly())
+            //     style += " eInpDis";
             return style; 
         }
 
@@ -324,37 +339,9 @@ public class TagEncodingHelper implement
         
         @Override
         public Object getAttributeEx(String name)
-        { 
-            Object value = getTagAttributeValue(name);
-            if (value==null)
-            {   // Check Column
-                value = getColumn().getAttribute(name);
-            }
-            // Checks whether it's another column    
-            if (value instanceof Column)
-            {   // Special case: Value is a column
-                Column col = ((Column)value);
-                Object rec = getRecord();
-                if (rec instanceof Record)
-                    return ((Record)rec).getValue(col);
-                else if (rec!=null)
-                {   // Get Value from a bean
-                    String property = col.getBeanPropertyName();
-                    try
-                    {   // Use Beanutils to get Property
-                        PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
-                        return pub.getSimpleProperty(rec, property);
-                    }
-                    catch (Exception e)
-                    {   log.error("BeanUtils.getSimpleProperty failed for "+property, e);
-                        return null;
-                    }
-                }    
-                return null;
-            }
-            return value;
+        {
+            return getAttributeValueEx(name);
         }
-        
     }
 
     // Logger
@@ -718,7 +705,7 @@ public class TagEncodingHelper implement
     public boolean isReadOnly()
     {
         // check attribute
-        Object val = getTagAttributeValue("disabled");
+        Object val = getAttributeValueEx("disabled");
         if (val != null && ObjectUtils.getBoolean(val))
             return true;
         // Check Record
@@ -1093,6 +1080,38 @@ public class TagEncodingHelper implement
     {
         return tag.getAttributes().get(name);
     }
+
+    public Object getAttributeValueEx(String name)
+    { 
+        Object value = getTagAttributeValue(name);
+        if (value==null)
+        {   // Check Column
+            value = getColumn().getAttribute(name);
+        }
+        // Checks whether it's another column    
+        if (value instanceof Column)
+        {   // Special case: Value is a column
+            Column col = ((Column)value);
+            Object rec = getRecord();
+            if (rec instanceof Record)
+                return ((Record)rec).getValue(col);
+            else if (rec!=null)
+            {   // Get Value from a bean
+                String property = col.getBeanPropertyName();
+                try
+                {   // Use Beanutils to get Property
+                    PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
+                    return pub.getSimpleProperty(rec, property);
+                }
+                catch (Exception e)
+                {   log.error("BeanUtils.getSimpleProperty failed for "+property, e);
+                    return null;
+                }
+            }    
+            return null;
+        }
+        return value;
+    }
     
     public String getTagAttributeString(String name, String defValue)
     {



Mime
View raw message