Author: jdonnerstag
Date: Sat Oct 17 10:47:33 2009
New Revision: 826222

URL: http://svn.apache.org/viewvc?rev=826222&view=rev
Log:
fixed CheckBoxMultipleChoice ignores isDisabled() checks
Issue: WICKET-2528

Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java?rev=826222&r1=826221&r2=826222&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBoxMultipleChoice.java
 Sat Oct 17 10:47:33 2009
@@ -206,7 +206,6 @@
                super(id, choices, renderer);
        }
 
-
        /**
         * Constructor
         * 
@@ -316,73 +315,90 @@
                {
                        // Get next choice
                        final T choice = choices.get(index);
+                       appendOptionHtml(buffer, choice, index, selected);
+               }
 
-                       Object displayValue = 
getChoiceRenderer().getDisplayValue(choice);
-                       Class<?> objectClass = displayValue == null ? null : 
displayValue.getClass();
-                       // Get label for choice
-                       String label = "";
-                       if (objectClass != null && objectClass != String.class)
+               // Replace body
+               replaceComponentTagBody(markupStream, openTag, buffer);
+       }
+
+       /**
+        * Generates and appends html for a single choice into the provided 
buffer
+        * 
+        * @param buffer
+        *            Appending string buffer that will have the generated html 
appended
+        * @param choice
+        *            Choice object
+        * @param index
+        *            The index of this option
+        * @param selected
+        *            The currently selected string value
+        */
+       @Override
+       protected void appendOptionHtml(final AppendingStringBuffer buffer, 
final T choice, int index,
+               final String selected)
+       {
+               Object displayValue = 
getChoiceRenderer().getDisplayValue(choice);
+               Class<?> objectClass = displayValue == null ? null : 
displayValue.getClass();
+               // Get label for choice
+               String label = "";
+               if (objectClass != null && objectClass != String.class)
+               {
+                       IConverter converter = getConverter(objectClass);
+                       label = converter.convertToString(displayValue, 
getLocale());
+               }
+               else if (displayValue != null)
+               {
+                       label = displayValue.toString();
+               }
+
+               // If there is a display value for the choice, then we know 
that the
+               // choice is automatic in some way. If label is /null/ then we 
know
+               // that the choice is a manually created checkbox tag at some 
random
+               // location in the page markup!
+               if (label != null)
+               {
+                       // Append option suffix
+                       buffer.append(getPrefix());
+
+                       String id = getChoiceRenderer().getIdValue(choice, 
index);
+                       final String idAttr = getMarkupId() + "-" + 
getInputName() + "_" + id;
+
+                       // Add checkbox element
+                       buffer.append("<input name=\"");
+                       buffer.append(getInputName());
+                       buffer.append("\"");
+                       buffer.append(" type=\"checkbox\"");
+                       if (isSelected(choice, index, selected))
                        {
-                               IConverter converter = 
getConverter(objectClass);
-                               label = converter.convertToString(displayValue, 
getLocale());
+                               buffer.append(" checked=\"checked\"");
                        }
-                       else if (displayValue != null)
+                       if (isDisabled(choice, index, selected))
                        {
-                               label = displayValue.toString();
+                               buffer.append(" disabled=\"disabled\"");
                        }
-
-                       // If there is a display value for the choice, then we 
know that the
-                       // choice is automatic in some way. If label is /null/ 
then we know
-                       // that the choice is a manually created checkbox tag 
at some random
-                       // location in the page markup!
-                       if (label != null)
+                       buffer.append(" value=\"");
+                       buffer.append(id);
+                       buffer.append("\" id=\"");
+                       buffer.append(idAttr);
+                       buffer.append("\"/>");
+
+                       // Add label for checkbox
+                       String display = label;
+                       if (localizeDisplayValues())
                        {
-                               // Append option suffix
-                               buffer.append(getPrefix());
+                               display = getLocalizer().getString(label, this, 
label);
+                       }
 
-                               String id = 
getChoiceRenderer().getIdValue(choice, index);
-                               final String idAttr = getMarkupId() + "-" + 
getInputName() + "_" + id;
+                       final CharSequence escaped = (getEscapeModelStrings() ? 
Strings.escapeMarkup(display,
+                               false, true) : display);
 
-                               // Add checkbox element
-                               buffer.append("<input name=\"")
-                                       .append(getInputName())
-                                       .append("\"")
-                                       .append(" type=\"checkbox\"")
-                                       .append((isSelected(choice, index, 
selected) ? " checked=\"checked\"" : ""))
-                                       .append((isEnabled() ? "" : " 
disabled=\"disabled\""))
-                                       .append(" value=\"")
-                                       .append(id)
-                                       .append("\" id=\"")
-                                       .append(idAttr)
-                                       .append("\"/>");
-
-                               // Add label for checkbox
-                               String display = label;
-                               if (localizeDisplayValues())
-                               {
-                                       display = 
getLocalizer().getString(label, this, label);
-                               }
-
-                               CharSequence escaped;
-                               if (getEscapeModelStrings())
-                               {
-                                       escaped = Strings.escapeMarkup(display, 
false, true);
-                               }
-                               else
-                               {
-                                       escaped = display;
-                               }
-
-                               buffer.append("<label for=\"");
-                               buffer.append(idAttr);
-                               
buffer.append("\">").append(escaped).append("</label>");
+                       buffer.append("<label for=\"");
+                       buffer.append(idAttr);
+                       buffer.append("\">").append(escaped).append("</label>");
 
-                               // Append option suffix
-                               buffer.append(getSuffix());
-                       }
+                       // Append option suffix
+                       buffer.append(getSuffix());
                }
-
-               // Replace body
-               replaceComponentTagBody(markupStream, openTag, buffer);
        }
 }


Reply via email to