empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1380888 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: components/ pageelements/ pages/ utils/
Date Tue, 04 Sep 2012 21:04:33 GMT
Author: doebele
Date: Tue Sep  4 21:04:33 2012
New Revision: 1380888

URL: http://svn.apache.org/viewvc?rev=1380888&view=rev
Log:
EMPIREDB-157 
JSF2 various small bugfixes

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/LabelTag.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/RecordPageElement.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.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/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=1380888&r1=1380887&r2=1380888&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 Sep  4 21:04:33 2012
@@ -368,6 +368,8 @@ public class ControlTag extends UIInput 
         if (parent.getChildCount() > 0)
         {
             labelComponent = (HtmlOutputLabel) parent.getChildren().get(0);
+            // update
+            helper.updateLabelComponent(context, labelComponent, null);
         }
         if (labelComponent == null)
         {

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LabelTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LabelTag.java?rev=1380888&r1=1380887&r2=1380888&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LabelTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LabelTag.java
Tue Sep  4 21:04:33 2012
@@ -60,6 +60,9 @@ public class LabelTag extends UIOutput /
         if (getChildCount() > 0)
         {
             labelComponent = (HtmlOutputLabel) getChildren().get(0);
+            // update
+            String forInput = helper.getTagAttribute("for");
+            helper.updateLabelComponent(context, labelComponent, forInput);
         }
         if (labelComponent == null)
         {

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=1380888&r1=1380887&r2=1380888&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 Sep  4 21:04:33 2012
@@ -25,6 +25,7 @@ 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.InternalException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.jsf2.app.FacesUtils;
@@ -79,6 +80,19 @@ public class RecordPageElement<T extends
         if (record.isValid()==false)
             reloadRecord();
     }
+
+    /**
+     * return true if the record can be restored from the session.
+     * @param newRecord flag to detect session data for a new reaord otherwise for an existing
record
+     * @return true if information to restore the record is available on the session
+     */
+    public boolean canReloadRecord(boolean newRecord)
+    {
+        if (newRecord)
+            return (getSessionObject(DBRecord.class)!=null);
+        else
+            return (getSessionObject(Object[].class)!=null); 
+    }
     
     /**
      * loads the record identified by the supplied key from the database<BR/>
@@ -169,7 +183,11 @@ public class RecordPageElement<T extends
             this.setSessionObject(Object[].class, record.getKeyValues());
             return true; 
             // OK
-        } catch(EmpireException e) {
+        } catch(Exception e) {
+            // Wrap exception
+            if (!(e instanceof EmpireException))
+                e = new InternalException(e);
+            // Set error Message
             FacesContext fc = FacesUtils.getContext();
             String msg = FacesUtils.getTextResolver(fc).getExceptionMessage(e);
             FacesUtils.addErrorMessage(fc, msg);

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java?rev=1380888&r1=1380887&r2=1380888&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java (original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/Page.java Tue
Sep  4 21:04:33 2012
@@ -33,6 +33,8 @@ import javax.faces.context.FacesContext;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBRowSet;
+import org.apache.empire.exceptions.EmpireException;
+import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.ItemNotFoundException;
 import org.apache.empire.jsf2.app.FacesApplication;
 import org.apache.empire.jsf2.app.FacesUtils;
@@ -258,7 +260,7 @@ public abstract class Page implements Se
     protected boolean handleActionError(String action, Throwable e)
     {
         // Set Faces Message
-        String msg = e.getLocalizedMessage();
+        String msg = getErrorMessage(e);
         String detail = extractErrorMessageDetail(action, e, 1);
         log.error(msg + "\r\n" + detail);
         FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detail);
@@ -271,6 +273,23 @@ public abstract class Page implements Se
         redirectTo(parentPage.getRedirect());
         return true;
     }
+
+    protected void setErrorMessage(Throwable e)
+    {
+        String msg = getErrorMessage(e);
+        String detail = extractErrorMessageDetail(action, e, 1);
+        log.error(msg + "\r\n" + detail, e);
+        FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, detail);
+        FacesContext.getCurrentInstance().addMessage(getPageName(), facesMsg);
+    }
+
+    protected String getErrorMessage(Throwable e)
+    {   // Wrap Exception
+        if (!(e instanceof EmpireException))
+            e = new InternalException(e);
+        // get message 
+        return getTextResolver().getExceptionMessage((Exception)e);
+    }
     
     protected String extractErrorMessageDetail(String action, Throwable e, int stackTraceElements)
     {

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java?rev=1380888&r1=1380887&r2=1380888&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PageNavigationHandler.java
Tue Sep  4 21:04:33 2012
@@ -118,7 +118,7 @@ public class PageNavigationHandler exten
                 n = s.lastIndexOf('?', i);
             if (n<0)
                 continue; // something is wrong
-            int v = s.indexOf('&');
+            int v = s.indexOf('&', i);
             String name = s.substring(n+1, i);
             String value = (v>i) ? s.substring(i+1, v) : s.substring(i+1);
             log.debug("Adding view parameter '{}' with value '{}'.", name, value);

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=1380888&r1=1380887&r2=1380888&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 Sep  4 21:04:33 2012
@@ -49,6 +49,7 @@ import org.apache.empire.data.RecordData
 import org.apache.empire.db.DBDatabase;
 import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBRowSet;
+import org.apache.empire.db.exceptions.FieldNotNullException;
 import org.apache.empire.exceptions.BeanPropertyGetException;
 import org.apache.empire.exceptions.BeanPropertySetException;
 import org.apache.empire.exceptions.InternalException;
@@ -273,8 +274,12 @@ public class TagEncodingHelper implement
         {
             // Make sure null values are not forced to be required
             boolean isNull = ObjectUtils.isEmpty(value);
-            if (isNull && !isRequired())
-                return;
+            if (isNull)
+            {   // Check Required
+                if (isRequired())
+                    throw new FieldNotNullException(column);
+                return; // not required
+            }
             // validate through column
             column.validate(value);
         }
@@ -1124,18 +1129,45 @@ public class TagEncodingHelper implement
         
         // required
         if (required)
-        {
-            HtmlPanelGroup span = new HtmlPanelGroup();
-            span.setStyleClass("required");
-            HtmlOutputText text = new HtmlOutputText();
-            text.setValue("*");
-            span.getChildren().add(text);
-            label.getChildren().add(span);
-        }
+            addRequiredMark(label);
 
         return label;
     }
     
+    public void updateLabelComponent(FacesContext context, HtmlOutputLabel label, String
forInput)
+    {
+        boolean hasMark = (label.getChildCount()>0);
+        // Find Input Control (only if forInput Attribute has been set!)
+        InputTag inputTag = null;
+        if (StringUtils.isNotEmpty(forInput) && !forInput.equals("*"))
+        {   // Set Label input Id
+            UIComponent input = FacesUtils.getFacesApplication().findComponent(context, forInput,
tag);
+            if (input!=null && (input instanceof InputTag))
+            {   // Check Read-Only
+                inputTag = ((InputTag)input);
+            }
+        }
+        // Is the Mark required?
+        boolean required = (inputTag!=null ? inputTag.isInputRequired() : isValueRequired());
+        if (required==hasMark)
+            return;
+        // Add or remove the mark
+        if (required)
+            addRequiredMark(label);
+        else
+            label.getChildren().clear();
+    }
+    
+    protected void addRequiredMark(HtmlOutputLabel label)
+    {
+        HtmlPanelGroup span = new HtmlPanelGroup();
+        span.setStyleClass("required");
+        HtmlOutputText text = new HtmlOutputText();
+        text.setValue("*");
+        span.getChildren().add(text);
+        label.getChildren().add(span);
+    }
+    
     /* ********************** CSS-generation ********************** */
 
     public static String getTagStyleClass(String tagCssStyle, String typeClass, String addlStyle,
String userStyle)



Mime
View raw message