Author: jbq Date: Wed Apr 25 14:52:09 2007 New Revision: 532497 URL: http://svn.apache.org/viewvc?view=rev&rev=532497 Log: WICKET-362 Add ability to manage disabled items from subclasses of AbstractChoice
Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.html incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.java Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java?view=diff&rev=532497&r1=532496&r2=532497 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/AbstractChoice.java Wed Apr 25 14:52:09 2007 @@ -309,6 +309,22 @@ protected abstract boolean isSelected(final Object object, int index, String selected); /** + * Gets whether the given value is disabled. This default implementation always returns false. + * + * @param object + * The object to check + * @param index + * The index in the choices collection this object is in. + * @param selected + * The currently selected string value + * @return Whether the given value represents the current selection + */ + protected boolean isDisabled(final Object object, int index, String selected) + { + return false; + } + + /** * Handle the container's body. * * @param markupStream @@ -360,6 +376,10 @@ if (isSelected(choice, index, selected)) { buffer.append("selected=\"selected\" "); + } + if (isDisabled(choice, index, selected)) + { + buffer.append("disabled=\"disabled\" "); } buffer.append("value=\""); buffer.append(renderer.getIdValue(choice, index)); Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.html?view=diff&rev=532497&r1=532496&r2=532497 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.html (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.html Wed Apr 25 14:52:09 2007 @@ -27,7 +27,7 @@ </td> </tr> <tr> - <td valign="top">Select some of these excellent choices</td> + <td valign="top">Select some of these excellent choices (note that choice 2 is disabled intentionally)</td> <td> <select wicket:id="choices"> <option>choice 1</option> Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.java?view=diff&rev=532497&r1=532496&r2=532497 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.java (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/compref/ListMultipleChoicePage.java Wed Apr 25 14:52:09 2007 @@ -75,7 +75,19 @@ ListMultipleChoice listChoice = new ListMultipleChoice("sites", SITES); form.add(listChoice); - listChoice = new ListMultipleChoice("choices", MANY_CHOICES).setMaxRows(5); + listChoice = new ListMultipleChoice("choices", MANY_CHOICES) { + /** + * @see org.apache.wicket.markup.html.form.AbstractChoice#isDisabled(java.lang.Object, int, java.lang.String) + */ + @Override + protected boolean isDisabled(Object object, int index, String selected) + { + if (index == 1) + return true; + return super.isDisabled(object, index, selected); + } + }; + listChoice.setMaxRows(5); form.add(listChoice); }