empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1379882 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: components/ controls/ pageelements/
Date Sat, 01 Sep 2012 22:29:19 GMT
Author: doebele
Date: Sat Sep  1 22:29:18 2012
New Revision: 1379882

URL: http://svn.apache.org/viewvc?rev=1379882&view=rev
Log:
EMPIREDB-168
JSF2 Input Controls: check for readOnly values and sync options in the select component

Modified:
    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/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/pageelements/RecordPageElement.java

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=1379882&r1=1379881&r2=1379882&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
Sat Sep  1 22:29:18 2012
@@ -455,9 +455,6 @@ public class ControlTag extends UIInput 
     {
         if (initState(context)==false)
             return;
-        // check disabled
-        if (inpInfo.isDisabled())
-            return;
         // get submitted value and validate
         if (log.isDebugEnabled())
             log.debug("Validating input for {}.", inpInfo.getColumn().getName());
@@ -481,9 +478,6 @@ public class ControlTag extends UIInput 
     {
         if (initState(context)==false)
             return;
-        // check disabled
-        if (inpInfo.isDisabled())
-            return;
         // No Action
         if (!isValid() || !isLocalValueSet())
             return; 

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=1379882&r1=1379881&r2=1379882&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
Sat Sep  1 22:29:18 2012
@@ -185,9 +185,6 @@ public class InputTag extends UIInput im
     {
         if (initState(context)==false)
             return;
-        // check disabled
-        if (inpInfo.isDisabled())
-            return;
         // get submitted value and validate
         if (log.isDebugEnabled())
             log.debug("Validating input for {}.", inpInfo.getColumn().getName());
@@ -212,9 +209,6 @@ public class InputTag extends UIInput im
     {
         if (initState(context)==false)
             return;
-        // check disabled
-        if (inpInfo.isDisabled())
-            return;
         // No Action
         if (!isValid() || !isLocalValueSet())
             return; 

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=1379882&r1=1379881&r2=1379882&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
Sat Sep  1 22:29:18 2012
@@ -33,6 +33,7 @@ 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;
@@ -271,6 +272,13 @@ public abstract class InputControl
         {
             if (value!=null) // && (!ObjectUtils.compareEqual(value, input.getLocalValue())
             {
+                // Disabled
+                if (ii.isDisabled())
+                {
+                    input.setSubmittedValue(null);
+                    throw new FieldIsReadOnlyException(ii.getColumn());
+                }    
+                // Save submitted value
                 FacesContext fc = FacesContext.getCurrentInstance();
                 Map<String, Object> reqMap = fc.getExternalContext().getRequestMap();
                 // Save submitted value

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=1379882&r1=1379881&r2=1379882&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
Sat Sep  1 22:29:18 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.empire.jsf2.controls;
 
+import java.util.Iterator;
 import java.util.List;
 
 import javax.faces.component.UIComponent;
@@ -83,11 +84,11 @@ public class SelectInputControl extends 
             copyAttributes(parent, ii, input);
             // disabled
             Object dis = ii.getAttribute("disabled");
-            if (dis!=null)
-                input.setDisabled(ObjectUtils.getBoolean(dis));
+            boolean disabled = (dis!=null) ? ObjectUtils.getBoolean(dis) : ii.isDisabled();

+            input.setDisabled(disabled);
             // Options
             Options options = ii.getOptions();
-            if (ii.isRequired()==false)
+            if (!ii.isRequired() && !(disabled && ii.getColumn().isRequired())
&& !options.contains(""))
             {   // Empty entry
                 options = new Options(options);
                 addSelectItem(input, ii, new OptionEntry("", getNullText(ii)));
@@ -109,13 +110,67 @@ public class SelectInputControl extends 
                 throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
             // cast
             input = (HtmlSelectOneMenu)comp;
+            // Options
+            syncOptions(input, ii);
         }
         
         // Set Value
-        input.setReadonly(ii.isDisabled());
         setInputValue(input, ii);
     }
     
+    private void syncOptions(HtmlSelectOneMenu input, InputInfo ii)
+    {
+        Options options = ii.getOptions();
+        boolean disabled = input.isDisabled();
+        boolean hasEmpty =(!ii.isRequired() && !(disabled && ii.getColumn().isRequired())
&& !options.contains(""));
+        // Compare child-items with options
+        Iterator<OptionEntry> ioe = options.iterator();
+        OptionEntry oe =(ioe.hasNext() ? ioe.next() : null);
+        List<UIComponent> childList = input.getChildren();
+        Iterator<UIComponent> ico = childList.iterator();
+        int lastIndex = 0;
+        while (ico.hasNext())
+        {
+            lastIndex++;
+            UIComponent co = ico.next(); 
+            if (!(co instanceof UISelectItem))
+                continue;
+            UISelectItem si = (UISelectItem)co;
+            Object ov = si.getItemValue();
+            if (ObjectUtils.isEmpty(ov) && hasEmpty)
+                continue;
+            if (oe==null)
+            {   // remove obsolete items
+                lastIndex--; 
+                for (int index = childList.size()-1; index>=lastIndex; index--)
+                    childList.remove(index);
+                // done
+                return;
+            }    
+            if (ObjectUtils.compareEqual(ov, oe.getValue()))
+            {   // next
+                oe =(ioe.hasNext() ? ioe.next() : null);
+                continue;
+            }    
+            // Not equal - do a full reload
+            input.getChildren().clear();
+            if (hasEmpty)
+                addSelectItem(input, ii, new OptionEntry("", getNullText(ii)));
+            for (OptionEntry e : options)
+            {   // Option entries
+                addSelectItem(input, ii, e);
+            }
+            // done
+            return;
+        }
+        // Are there any items left?
+        while(oe!=null)
+        {   // add missing item
+            addSelectItem(input, ii, oe);
+            oe =(ioe.hasNext() ? ioe.next() : null);
+        }
+    }
+    
     private String getNullText(InputInfo ii)
     {
         String nullText = getFormatString(ii, FORMAT_NULL, FORMAT_NULL_ATTRIBUTE);

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=1379882&r1=1379881&r2=1379882&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
Sat Sep  1 22:29:18 2012
@@ -25,6 +25,7 @@ import javax.faces.component.html.HtmlIn
 import javax.faces.context.FacesContext;
 
 import org.apache.empire.commons.ObjectUtils;
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
 
@@ -97,6 +98,32 @@ public class TextAreaInputControl extend
         
     }
 
+    @Override
+    protected String formatValue(Object value, ValueInfo vi)
+    {
+        String strVal = super.formatValue(value, vi);
+        // replace CR/LF by <BR/>
+        if (strVal.indexOf("\r\n")>0)
+        {   // replace CR with <BR/>
+            strVal = StringUtils.replace(strVal, "\r\n", "<BR/>\n");
+        }
+        else if (strVal.indexOf('\n')>0)
+        {   // replace CR with <BR/>
+            strVal = StringUtils.replace(strVal, "\n", "<BR/>\n");
+        }
+        return strVal; 
+    }
+
+    @Override
+    protected Object parseInputValue(String value, InputInfo ii)
+    {
+        // Trim
+        if (hasFormatOption(ii, "notrim")==false)
+            value = value.trim();
+        // Done 
+        return value; 
+    }
+
     /*
     private int getTextareaCols(InputInfo ii)
     {
@@ -104,4 +131,6 @@ public class TextAreaInputControl extend
     }
     */
     
+    
+    
 }

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=1379882&r1=1379881&r2=1379882&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
Sat Sep  1 22:29:18 2012
@@ -133,6 +133,9 @@ public class TextInputControl extends In
     @Override
     protected Object parseInputValue(String value, InputInfo ii)
     {
+        // Trim
+        if (hasFormatOption(ii, "notrim")==false)
+            value = value.trim();
         // Check Data Type
         Column column = ii.getColumn();
         DataType type = column.getDataType();

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java?rev=1379882&r1=1379881&r2=1379882&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
Sat Sep  1 22:29:18 2012
@@ -62,6 +62,15 @@ public class RecordPageElement<T extends
     {
         return record.getRowSet();
     }
+    
+    public String getRecordIdParam()
+    {
+        if (!record.isValid())
+            return null;
+        // idParam
+        Object[] key = record.getKeyValues();
+        return getPage().getIdParamForKey(rowset, key);
+    }
 
     @Override
     protected void onInitPage()
@@ -81,7 +90,14 @@ public class RecordPageElement<T extends
         // Check Key
         if (recKey==null || recKey.length==0)
         {   // Invalid Record key
-            throw new ObjectNotValidException(this);
+            T rec = (T)getSessionObject(DBRecord.class);
+            if (rec!=null)
+            {   // A new record
+                record = rec;
+                return;
+            }    
+            // Not Valid
+            throw new ObjectNotValidException(record);
         }
         // Record laden
         Connection conn = getPage().getConnection(rowset.getDatabase()); 
@@ -100,12 +116,38 @@ public class RecordPageElement<T extends
             throw new InvalidArgumentException("recKey", recKey);
         }
         // Put key on Session
+        this.removeSessionObject(DBRecord.class);
         this.setSessionObject(Object[].class, recKey);
         // Record laden
         Connection conn = getPage().getConnection(rowset.getDatabase()); 
         record.read(rowset, recKey, conn);
     }
 
+    /**
+     * loads an existing record
+     * @param idParam
+     */
+    public void loadRecord(String idParam)
+    {
+        Object[] key = getPage().getKeyFromParam(rowset, idParam);
+        loadRecord(key);
+    }
+    
+    /**
+     * creates a new record
+     */
+    public void createRecord()
+    {
+        Connection conn = getPage().getConnection(rowset.getDatabase()); 
+        record.create(rowset, conn);
+        // Put key on Session
+        this.removeSessionObject(Object[].class);
+        this.setSessionObject(DBRecord.class, record);
+    }
+
+    /**
+     * updates or inserts the record in the database
+     */
     public boolean updateRecord()
     {
         // Record laden
@@ -123,6 +165,7 @@ public class RecordPageElement<T extends
             Connection conn = getPage().getConnection(rowset.getDatabase()); 
             record.update(conn);
             // Put key on Session
+            this.removeSessionObject(DBRecord.class);
             this.setSessionObject(Object[].class, record.getKeyValues());
             return true; 
             // OK
@@ -135,31 +178,30 @@ public class RecordPageElement<T extends
     }
     
     /**
-     * creates a new record
+     * deletes a record
      */
-    public void createRecord()
+    public void deleteRecord()
     {
-        record.create(rowset);
+        // check valid
+        if (!record.isValid())
+            throw new ObjectNotValidException(record);
+        // delete
+        Connection conn = getPage().getConnection(rowset.getDatabase()); 
+        record.delete(conn);
+        // Put key on Session
+        this.removeSessionObject(Object[].class);
+        this.removeSessionObject(DBRecord.class);
     }
-
+    
     /**
-     * loads an existing record
-     * @param idParam
+     * closes a record
      */
-    public void loadRecord(String idParam)
+    public void closeRecord()
     {
-        Object[] key = getPage().getKeyFromParam(rowset, idParam);
-
-        loadRecord(key);
-    }
-    
-    public String getRecordIdParam()
-    {
-        if (!record.isValid())
-            return null;
-        // idParam
-        Object[] key = record.getKeyValues();
-        return getPage().getIdParamForKey(rowset, key);
+        record.close();
+        // Put key on Session
+        this.removeSessionObject(Object[].class);
+        this.removeSessionObject(DBRecord.class);
     }
 
 }



Mime
View raw message