empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1375832 - /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
Date Tue, 21 Aug 2012 22:33:07 GMT
Author: doebele
Date: Tue Aug 21 22:33:06 2012
New Revision: 1375832

URL: http://svn.apache.org/viewvc?rev=1375832&view=rev
Log:
EMPIREDB-161
RecordPageElement Update method with error handling

Modified:
    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/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=1375832&r1=1375831&r2=1375832&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
Tue Aug 21 22:33:06 2012
@@ -20,10 +20,14 @@ package org.apache.empire.jsf2.pageeleme
 
 import java.sql.Connection;
 
+import javax.faces.context.FacesContext;
+
 import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBRowSet;
+import org.apache.empire.exceptions.EmpireException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.jsf2.app.FacesUtils;
 import org.apache.empire.jsf2.pages.Page;
 import org.apache.empire.jsf2.pages.PageElement;
 import org.slf4j.Logger;
@@ -102,6 +106,34 @@ public class RecordPageElement<T extends
         record.read(rowset, recKey, conn);
     }
 
+    public boolean updateRecord()
+    {
+        // Record laden
+        try {
+            // Check Key
+            if (record.isValid()==false)
+            {   // Invalid Record key
+                throw new ObjectNotValidException(record); 
+            }
+            // Check Modified
+            if (record.isModified()==false)
+            {   // Not Modified
+                return true; 
+            }
+            Connection conn = getPage().getConnection(rowset.getDatabase()); 
+            record.update(conn);
+            // Put key on Session
+            this.setSessionObject(Object[].class, record.getKeyValues());
+            return true; 
+            // OK
+        } catch(EmpireException e) {
+            FacesContext fc = FacesUtils.getContext();
+            String msg = FacesUtils.getTextResolver(fc).getExceptionMessage(e);
+            FacesUtils.addErrorMessage(fc, msg);
+            return false; 
+        }
+    }
+    
     /**
      * creates a new record
      */



Mime
View raw message