empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1385259 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: components/LinkTag.java components/NbspTag.java components/TitleTag.java controls/InputControl.java utils/TagEncodingHelper.java
Date Sun, 16 Sep 2012 13:28:46 GMT
Author: doebele
Date: Sun Sep 16 13:28:46 2012
New Revision: 1385259

URL: http://svn.apache.org/viewvc?rev=1385259&view=rev
Log:
EMPIREDB-157 
JSF2 allow input-control to provide different input-id for the label's "for"-attribute

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/NbspTag.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/TitleTag.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/components/LinkTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java?rev=1385259&r1=1385258&r2=1385259&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/LinkTag.java
Sun Sep 16 13:28:46 2012
@@ -22,7 +22,6 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
-import javax.faces.component.NamingContainer;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UINamingContainer;
 import javax.faces.component.UIOutput;
@@ -41,7 +40,7 @@ import org.apache.empire.jsf2.utils.TagE
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class LinkTag extends UIOutput implements NamingContainer
+public class LinkTag extends UIOutput // implements NamingContainer
 {
     // or HtmlOutcomeTargetLink
     // or HtmlOutputLink

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/NbspTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/NbspTag.java?rev=1385259&r1=1385258&r2=1385259&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/NbspTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/NbspTag.java
Sun Sep 16 13:28:46 2012
@@ -20,7 +20,6 @@ package org.apache.empire.jsf2.component
 
 import java.io.IOException;
 
-import javax.faces.component.NamingContainer;
 import javax.faces.component.UINamingContainer;
 import javax.faces.component.UIOutput;
 import javax.faces.context.FacesContext;
@@ -28,7 +27,7 @@ import javax.faces.context.ResponseWrite
 
 import org.apache.empire.commons.ObjectUtils;
 
-public class NbspTag extends UIOutput implements NamingContainer
+public class NbspTag extends UIOutput // implements NamingContainer
 {
     // private int count = 1;
 

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/TitleTag.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/TitleTag.java?rev=1385259&r1=1385258&r2=1385259&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/TitleTag.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/TitleTag.java
Sun Sep 16 13:28:46 2012
@@ -21,7 +21,6 @@ package org.apache.empire.jsf2.component
 import java.io.IOException;
 import java.util.Map;
 
-import javax.faces.component.NamingContainer;
 import javax.faces.component.UIOutput;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -33,7 +32,7 @@ import org.apache.empire.jsf2.utils.TagE
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TitleTag extends UIOutput implements NamingContainer
+public class TitleTag extends UIOutput // implements NamingContainer
 {
     // Logger
     private static final Logger log = LoggerFactory.getLogger(TitleTag.class);

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=1385259&r1=1385258&r2=1385259&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
Sun Sep 16 13:28:46 2012
@@ -230,6 +230,11 @@ public abstract class InputControl
     {
         return name;
     }
+    
+    public String getLabelForId(InputInfo ii)
+    {
+        return ii.getInputId();
+    }
 
     /* Value */
     public void renderValue(ValueInfo vi, ResponseWriter writer)

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=1385259&r1=1385258&r2=1385259&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
Sun Sep 16 13:28:46 2012
@@ -20,6 +20,7 @@ package org.apache.empire.jsf2.utils;
 
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
 import java.util.Locale;
 
 import javax.el.ValueExpression;
@@ -326,6 +327,10 @@ public class TagEncodingHelper implement
         public String getStyleClass(String addlStyle)
         {
             String style = getTagStyleClass(addlStyle);
+            if (hasError)
+            {   // Invalid
+                style = "eInvalid "+style;
+            }
             return style; 
         }
 
@@ -358,6 +363,7 @@ public class TagEncodingHelper implement
     private TextResolver        textResolver = null;
     private Object              mostRecentValue = null;
     private boolean             skipValidation = false;
+    private boolean             hasError = false;
 
     public TagEncodingHelper(UIOutput tag, String tagCssStyle)
     {
@@ -487,6 +493,8 @@ public class TagEncodingHelper implement
     {
         // Skip validate
         skipValidation = FacesUtils.isSkipInputValidation(ctx);
+        // check whether we have got an error
+        hasError = detectError(ctx);            
         // create
         return new InputInfoImpl(getColumn(), getTextResolver(ctx));
     }
@@ -1076,6 +1084,18 @@ public class TagEncodingHelper implement
         return textResolver;
     }
     
+    private boolean detectError(FacesContext context)
+    {
+        Iterator<FacesMessage> iter = context.getMessages(tag.getClientId());
+        while (iter.hasNext())
+        {   // Check for error
+            FacesMessage m = iter.next();
+            if (m.getSeverity()==FacesMessage.SEVERITY_ERROR)
+                return true;
+        }
+        return false;
+    }
+    
     public void addErrorMessage(FacesContext context, Exception e)
     {
         String msgText = getTextResolver(context).getExceptionMessage(e);
@@ -1176,6 +1196,10 @@ public class TagEncodingHelper implement
                 readOnly = inputTag.isInputReadOnly();
                 required = inputTag.isInputRequired();
             }
+            else
+            {   // Not found (<e:input id="ABC"...> must match <e:label for="ABC"...>
+                log.warn("Input component {} not found for label {}.", forInput, getColumn().getName());
+            }
         }
         if (column==null)
         {   // Get from LinkTag
@@ -1211,11 +1235,19 @@ public class TagEncodingHelper implement
         // for 
         if (StringUtils.isNotEmpty(forInput) && !readOnly)
         {   // Set Label input Id
-            String inputId = getInputInfo(context).getInputId();
-            if (forInput.equals("*"))
-                label.setFor(inputId);
+            InputControl.InputInfo ii = getInputInfo(context);
+            String inputId = getInputControl().getLabelForId(ii);
+            if (StringUtils.isNotEmpty(inputId))
+            {   // input_id was given
+                if (forInput.equals("*"))
+                    label.setFor(inputId);
+                else
+                    label.setFor(forInput+":"+inputId);
+            }
             else
-                label.setFor(forInput+":"+inputId);
+            {   // No input-id available
+                log.info("No input-id provided for {}.", getColumn().getName());
+            }    
         }    
 
         // style



Mime
View raw message