empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1380296 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2: components/SelectTag.java controls/InputControl.java controls/SelectInputControl.java utils/TagEncodingHelper.java
Date Mon, 03 Sep 2012 17:02:32 GMT
Author: doebele
Date: Mon Sep  3 17:02:32 2012
New Revision: 1380296

URL: http://svn.apache.org/viewvc?rev=1380296&view=rev
Log:
EMPIREDB-168 
Bugfix: SelectTag made to behave like SelectInputControl

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/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/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=1380296&r1=1380295&r2=1380296&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
Mon Sep  3 17:02:32 2012
@@ -22,14 +22,11 @@ import java.io.IOException;
 import java.util.Map;
 
 import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
-import javax.faces.component.UISelectItem;
 import javax.faces.component.html.HtmlSelectOneMenu;
 import javax.faces.context.FacesContext;
 
 import org.apache.empire.commons.ObjectUtils;
-import org.apache.empire.commons.OptionEntry;
 import org.apache.empire.commons.Options;
 import org.apache.empire.commons.StringUtils;
 import org.apache.empire.jsf2.app.FacesUtils;
@@ -62,14 +59,31 @@ public class SelectTag extends UIInput i
     {
         // add label and input components when the view is loaded for the first time
         UIInput inputComponent = null;
+        TextResolver textResolver = FacesUtils.getTextResolver(context);
         if (getChildCount() > 0)
         {
             inputComponent = getInputComponent();
+            if (inputComponent instanceof HtmlSelectOneMenu)
+            {
+                SelectInputControl control = (SelectInputControl)InputControlManager.getControl(SelectInputControl.NAME);
+                // disabled
+                boolean disabled = isDisabled();
+                ((HtmlSelectOneMenu)inputComponent).setDisabled(disabled);
+                // Options (sync)
+                Options options = getOptionList();
+                boolean hasEmpty = isAllowNull() && !options.contains("");
+                control.syncOptions((HtmlSelectOneMenu)inputComponent, textResolver, options,
hasEmpty, getNullText());
+            }
+            else
+            {   // Something's wrong here?
+                log.warn("WARN: Unexpected child node for {}! Child item type is {}.", getClass().getName(),
inputComponent.getClass().getName());
+                inputComponent = null;
+            }
         }
         if (inputComponent == null)
         {
-            inputComponent = createSelectOneMenu(FacesUtils.getTextResolver(context));
-            this.getChildren().add(inputComponent);
+            inputComponent = createSelectOneMenu(textResolver);
+            this.getChildren().add(0, inputComponent);
         }
         // render components
         inputComponent.encodeAll(context);
@@ -160,18 +174,11 @@ public class SelectTag extends UIInput i
         copyAttributes(input);
         // Options
         Options options = getOptionList();
-        if (isAllowNull())
-        { // Empty entry
-            options = new Options(options);
-            addSelectItem(input, textResolver, new OptionEntry("", getNullText()));
-        }
-        for (OptionEntry e : options)
-        { // Option entries
-            addSelectItem(input, textResolver, e);
-        }
-        // input.setReadonly(isReadOnly());
-        if (isDisabled())
-            input.setDisabled(true);
+        boolean addEmpty = isAllowNull() && !options.contains("");
+        control.initOptions(input, textResolver, options, addEmpty, getNullText());
+        // disabled
+        boolean disabled = isDisabled();
+        input.setDisabled(disabled);
         // input.setLabel(getLabelString());
         // input.setRequired(col.isRequired() && !col.isAutoGenerated());
         // input.setId(this.getId() + INPUT_SUFFIX);
@@ -190,18 +197,5 @@ public class SelectTag extends UIInput i
         if ((value = attr.get("onchange")) != null)
             input.setOnchange(StringUtils.toString(value));
     }
-
-    private void addSelectItem(UIComponent input, TextResolver textResolver, OptionEntry
e)
-    {
-        UISelectItem selectItem = new UISelectItem();
-        // set value
-        selectItem.setItemValue(e.getValueString());
-        // set text
-        String text = e.getText();
-        text = textResolver.resolveText(text);
-        selectItem.setItemLabel(text);
-        // add item
-        input.getChildren().add(selectItem);
-    }
-
+    
 }

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=1380296&r1=1380295&r2=1380296&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
Mon Sep  3 17:02:32 2012
@@ -37,6 +37,7 @@ import org.apache.empire.db.exceptions.F
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
+import org.apache.empire.jsf2.app.TextResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -180,6 +181,7 @@ public abstract class InputControl
         String getFormat();    // Custom Formatting options specific to each InputControl-type
         Locale getLocale();
         String getText(String key);
+        TextResolver getTextResolver();
         /*
         Object getNullValue();
         String getOnclick();

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=1380296&r1=1380295&r2=1380296&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
Mon Sep  3 17:02:32 2012
@@ -32,6 +32,7 @@ import org.apache.empire.commons.Options
 import org.apache.empire.data.Column;
 import org.apache.empire.exceptions.InternalException;
 import org.apache.empire.exceptions.UnexpectedReturnValueException;
+import org.apache.empire.jsf2.app.TextResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -88,18 +89,9 @@ public class SelectInputControl extends 
             input.setDisabled(disabled);
             // Options
             Options options = ii.getOptions();
-            if (!ii.isRequired() && !(disabled && ii.getColumn().isRequired())
&& !options.contains(""))
-            {   // Empty entry
-                options = new Options(options);
-                addSelectItem(input, ii, new OptionEntry("", getNullText(ii)));
-            }
-            if (options!=null && options.size()>0)
-            {   // Add options
-                for (OptionEntry e : options)
-                { // Option entries
-                    addSelectItem(input, ii, e);
-                }
-            }
+            boolean hasEmpty =(!ii.isRequired() && !(disabled && ii.getColumn().isRequired())
&& !options.contains(""));
+            String nullText = (hasEmpty) ? getNullText(ii) : "";
+            initOptions(input, ii.getTextResolver(), options, hasEmpty, nullText);
             // add
             compList.add(input);
         }
@@ -110,19 +102,39 @@ public class SelectInputControl extends 
                 throw new UnexpectedReturnValueException(comp.getClass().getName(), "compList.get");
             // cast
             input = (HtmlSelectOneMenu)comp;
-            // Options
-            syncOptions(input, ii);
+            // disabled
+            // boolean disabled = input.isDisabled();
+            Object dis = ii.getAttribute("disabled");
+            boolean disabled = (dis!=null) ? ObjectUtils.getBoolean(dis) : ii.isDisabled();

+            input.setDisabled(disabled);
+            // Options (sync)
+            Options options = ii.getOptions();
+            boolean hasEmpty =(!ii.isRequired() && !(disabled && ii.getColumn().isRequired())
&& !options.contains(""));
+            String nullText = (hasEmpty) ? getNullText(ii) : "";
+            syncOptions(input, ii.getTextResolver(), options, hasEmpty, nullText);
         }
         
         // Set Value
         setInputValue(input, ii);
     }
+
+    public void initOptions(HtmlSelectOneMenu input, TextResolver textResolver, Options options,
boolean addEmpty, String nullText)
+    {
+        if (addEmpty)
+        {   // Empty entry
+            addSelectItem(input, textResolver, new OptionEntry("", nullText));
+        }
+        if (options!=null && options.size()>0)
+        {   // Add options
+            for (OptionEntry e : options)
+            { // Option entries
+                addSelectItem(input, textResolver, e);
+            }
+        }
+    }
     
-    private void syncOptions(HtmlSelectOneMenu input, InputInfo ii)
+    public void syncOptions(HtmlSelectOneMenu input, TextResolver textResolver, Options options,
boolean hasEmpty, String nullText)
     {
-        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);
@@ -155,10 +167,10 @@ public class SelectInputControl extends 
             // Not equal - do a full reload
             input.getChildren().clear();
             if (hasEmpty)
-                addSelectItem(input, ii, new OptionEntry("", getNullText(ii)));
+                addSelectItem(input, textResolver, new OptionEntry("", nullText));
             for (OptionEntry e : options)
             {   // Option entries
-                addSelectItem(input, ii, e);
+                addSelectItem(input, textResolver, e);
             }
             // done
             return;
@@ -166,29 +178,29 @@ public class SelectInputControl extends 
         // Are there any items left?
         while(oe!=null)
         {   // add missing item
-            addSelectItem(input, ii, oe);
+            addSelectItem(input, textResolver, oe);
             oe =(ioe.hasNext() ? ioe.next() : null);
         }
     }
-    
-    private String getNullText(InputInfo ii)
-    {
-        String nullText = getFormatString(ii, FORMAT_NULL, FORMAT_NULL_ATTRIBUTE);
-        return (nullText!=null) ? ii.getText(nullText) : "";
-    }
 
-    private void addSelectItem(UIComponent input, InputInfo ii, OptionEntry e)
+    public void addSelectItem(UIComponent input, TextResolver textResolver, OptionEntry e)
     {
         UISelectItem selectItem = new UISelectItem();
         // set value
         selectItem.setItemValue(e.getValueString());
         // set text
         String text = e.getText();
-        text = ii.getText(text);
+        text = textResolver.resolveText(text);
         selectItem.setItemLabel(text);
         // add item
         input.getChildren().add(selectItem);
     }
+    
+    private String getNullText(InputInfo ii)
+    {
+        String nullText = getFormatString(ii, FORMAT_NULL, FORMAT_NULL_ATTRIBUTE);
+        return (nullText!=null) ? ii.getText(nullText) : "";
+    }
 
     @Override
     protected String formatValue(Object value, ValueInfo vi)

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=1380296&r1=1380295&r2=1380296&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
Mon Sep  3 17:02:32 2012
@@ -247,6 +247,12 @@ public class TagEncodingHelper implement
         {
             return textResolver.resolveText(text);
         }
+
+        @Override
+        public TextResolver getTextResolver()
+        {
+            return textResolver;
+        }
     }
 
     private class InputInfoImpl extends ValueInfoImpl implements InputControl.InputInfo



Mime
View raw message