Author: ehillenius Date: Mon Jul 2 12:40:35 2007 New Revision: 552572 URL: http://svn.apache.org/viewvc?view=rev&rev=552572 Log: WICKET-716
Modified: incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/DropDownChoice.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.html incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInputModel.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/Multiply.java Modified: incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateField.java Mon Jul 2 12:40:35 2007 @@ -62,7 +62,7 @@ } /** - * Gets the converted input. In this case, we're really just interested in + * Sets the converted input. In this case, we're really just interested in * the nested date field, as that is the element that receives the real user * input. So we're just passing that on. * <p> @@ -76,11 +76,11 @@ * * @return instance of [EMAIL PROTECTED] Date}, possibly null * - * @see org.apache.wicket.markup.html.form.FormComponent#getConvertedInput() + * @see org.apache.wicket.markup.html.form.FormComponent#convertInput() */ - public Object getConvertedInput() + protected void convertInput() { - return dateField.getConvertedInput(); + setConvertedInput(dateField.getConvertedInput()); } /** Modified: incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/DateTimeField.java Mon Jul 2 12:40:35 2007 @@ -124,67 +124,6 @@ } /** - * Gets the converted input. It combines the inputs of the nested date, - * hours, minutes and am/pm fields and constructs a date from it. - * <p> - * Note that overriding this method is a better option than overriding - * [EMAIL PROTECTED] #updateModel()} like the first versions of this class did. The - * reason for that is that this method can be used by form validators - * without having to depend on the actual model being updated, and this - * method is called by the default implementation of [EMAIL PROTECTED] #updateModel()} - * anyway (so we don't have to override that anymore). - * </p> - * - * @return instance of [EMAIL PROTECTED] Date}, possibly null - * - * @see org.apache.wicket.markup.html.form.FormComponent#getConvertedInput() - */ - public Object getConvertedInput() - { - Object dateFieldInput = dateField.getConvertedInput(); - if (dateFieldInput != null) - { - MutableDateTime date = new MutableDateTime(dateFieldInput); - Integer hours = (Integer)hoursField.getConvertedInput(); - Integer minutes = (Integer)minutesField.getConvertedInput(); - AM_PM amOrPm = (AM_PM)amOrPmChoice.getConvertedInput(); - - try - { - TimeZone zone = getClientTimeZone(); - if (zone != null) - { - date.setZone(DateTimeZone.forTimeZone(zone)); - } - - if (hours != null) - { - date.set(DateTimeFieldType.hourOfHalfday(), hours.intValue() % 12); - date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0); - } - if (amOrPm == AM_PM.PM) - { - date.set(DateTimeFieldType.halfdayOfDay(), 1); - } - else - { - date.set(DateTimeFieldType.halfdayOfDay(), 0); - } - - // the date will be in the server's timezone - return date.toDate(); - } - catch (RuntimeException e) - { - DateTimeField.this.error(e.getMessage()); - invalid(); - } - } - - return null; - } - - /** * Gets date. * * @return date @@ -288,6 +227,67 @@ minutesField.setLabel(new Model("minutes")); add(amOrPmChoice = new DropDownChoice("amOrPmChoice", new PropertyModel(this, "amOrPm"), Arrays.asList(AM_PM.values()))); + } + + /** + * Sets the converted input, which is an instance of [EMAIL PROTECTED] Date}, possibly + * null. It combines the inputs of the nested date, hours, minutes and am/pm + * fields and constructs a date from it. + * <p> + * Note that overriding this method is a better option than overriding + * [EMAIL PROTECTED] #updateModel()} like the first versions of this class did. The + * reason for that is that this method can be used by form validators + * without having to depend on the actual model being updated, and this + * method is called by the default implementation of [EMAIL PROTECTED] #updateModel()} + * anyway (so we don't have to override that anymore). + * </p> + * + * @see org.apache.wicket.markup.html.form.FormComponent#convertInput() + */ + protected void convertInput() + { + Object convertedInput = null; + Object dateFieldInput = dateField.getConvertedInput(); + if (dateFieldInput != null) + { + MutableDateTime date = new MutableDateTime(dateFieldInput); + Integer hours = (Integer)hoursField.getConvertedInput(); + Integer minutes = (Integer)minutesField.getConvertedInput(); + AM_PM amOrPm = (AM_PM)amOrPmChoice.getConvertedInput(); + + try + { + TimeZone zone = getClientTimeZone(); + if (zone != null) + { + date.setZone(DateTimeZone.forTimeZone(zone)); + } + + if (hours != null) + { + date.set(DateTimeFieldType.hourOfHalfday(), hours.intValue() % 12); + date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0); + } + if (amOrPm == AM_PM.PM) + { + date.set(DateTimeFieldType.halfdayOfDay(), 1); + } + else + { + date.set(DateTimeFieldType.halfdayOfDay(), 0); + } + + // the date will be in the server's timezone + convertedInput = date.toDate(); + } + catch (RuntimeException e) + { + DateTimeField.this.error(e.getMessage()); + invalid(); + } + } + + setConvertedInput(convertedInput); } /** Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckBox.java Mon Jul 2 12:40:35 2007 @@ -72,7 +72,7 @@ */ public void onSelectionChanged() { - convert(); + convertInput(); updateModel(); onSelectionChanged(getModelObject()); } Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/CheckGroup.java Mon Jul 2 12:40:35 2007 @@ -192,7 +192,7 @@ */ public final void onSelectionChanged() { - convert(); + convertInput(); updateModel(); onSelectionChanged((Collection)getModelObject()); } Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/DropDownChoice.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/DropDownChoice.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/DropDownChoice.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/DropDownChoice.java Mon Jul 2 12:40:35 2007 @@ -150,7 +150,7 @@ */ public final void onSelectionChanged() { - convert(); + convertInput(); updateModel(); onSelectionChanged(getModelObject()); } Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java Mon Jul 2 12:40:35 2007 @@ -74,7 +74,9 @@ * @author Johan Compagner * @author Igor Vaynberg (ivaynberg) */ -public abstract class FormComponent extends LabeledWebMarkupContainer implements IFormVisitorParticipant +public abstract class FormComponent extends LabeledWebMarkupContainer + implements + IFormVisitorParticipant { /** * Visitor for traversing form components @@ -541,19 +543,30 @@ } /** - * Gets the converter input. You typically should not override this method, - * unless you are writing a - * [EMAIL PROTECTED] FormComponentPanel special form component} that embeds other form - * components that receive the real user input. + * Gets the converted input. The converted input is set earlier though the + * implementation of [EMAIL PROTECTED] #convertInput()}. * - * @return value of input converted into appropriate type if any was set + * @return value of input possibly converted into an appropriate type */ - public Object getConvertedInput() + public final Object getConvertedInput() { return convertedInput; } /** + * Sets the converted input. This method is typically not called by clients, + * unless they override [EMAIL PROTECTED] #convertInput()}, in which case they should + * call this method to update the input for this component instance. + * + * @param convertedInput + * the converted input + */ + public final void setConvertedInput(Object convertedInput) + { + this.convertedInput = convertedInput; + } + + /** * @return The parent form for this form component */ public Form getForm() @@ -722,9 +735,10 @@ } /** - * This method can be called to know if this component really has raw input. + * Returns whether this component has raw input. Raw input is unconverted + * input straight from the client. * - * @return boolean if this form component has rawinput. + * @return boolean whether this component has raw input. */ public final boolean hasRawInput() { @@ -869,7 +883,7 @@ updateModel(); } } - + /** * The value will be made available to the validator property by means of * ${label}. It does not have any specific meaning to FormComponent itself. @@ -925,8 +939,8 @@ } else { - throw new UnsupportedOperationException("FormComponent " + getClass() - + " does not support cookies"); + throw new UnsupportedOperationException("FormComponent " + getClass() + + " does not support cookies"); } return this; } @@ -1008,8 +1022,8 @@ validateRequired(); if (isValid()) { - convert(); - + convertInput(); + if (isValid()) { validateValidators(); @@ -1094,7 +1108,7 @@ * errors. Converted value is available through * [EMAIL PROTECTED] FormComponent#getConvertedInput()} */ - protected final void convert() + protected void convertInput() { if (typeName == null) { @@ -1217,8 +1231,9 @@ } catch (NumberFormatException e) { - throw new IllegalArgumentException(exceptionMessage("Internal error. Request string '" - + string + "' not a valid integer")); + throw new IllegalArgumentException( + exceptionMessage("Internal error. Request string '" + string + + "' not a valid integer")); } } @@ -1242,8 +1257,8 @@ } catch (NumberFormatException e) { - throw new IllegalArgumentException(exceptionMessage("Request string '" + string - + "' is not a valid integer")); + throw new IllegalArgumentException(exceptionMessage("Request string '" + string + + "' is not a valid integer")); } } else @@ -1301,6 +1316,11 @@ super.onComponentTag(tag); } + /** + * Sets the temporary converted input value to null. + * + * @see org.apache.wicket.Component#onDetach() + */ protected void onDetach() { super.onDetach(); @@ -1368,13 +1388,13 @@ IValidator validator = null; boolean isNull = getConvertedInput() == null; - + try { for (i = 0; i < size; i++) { validator = validators_get(i); - + if (isNull == false || validator instanceof INullAcceptingValidator) { validator.validate(validatable); @@ -1387,8 +1407,8 @@ } catch (Exception e) { - throw new WicketRuntimeException("Exception '" + e + "' occurred during validation " - + validator.getClass().getName() + " on component " + this.getPath(), e); + throw new WicketRuntimeException("Exception '" + e + "' occurred during validation " + + validator.getClass().getName() + " on component " + this.getPath(), e); } } Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioChoice.java Mon Jul 2 12:40:35 2007 @@ -308,7 +308,7 @@ */ public void onSelectionChanged() { - convert(); + convertInput(); updateModel(); onSelectionChanged(getModelObject()); } Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java (original) +++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/RadioGroup.java Mon Jul 2 12:40:35 2007 @@ -136,7 +136,7 @@ */ public final void onSelectionChanged() { - convert(); + convertInput(); updateModel(); onSelectionChanged(getModelObject()); } Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.html?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.html (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.html Mon Jul 2 12:40:35 2007 @@ -23,10 +23,7 @@ <label for="integerProperty"><wicket:message key="integer" /></label> <input wicket:id="integerProperty" id="integerProperty" type="text" size="40"/> <label for="doubleProperty"><wicket:message key="double" /></label> - <input wicket:id="doubleProperty" id="doubleProperty" type="text" size="40"/> - - <label for="dateProperty"><wicket:message key="date" /></label> - <input type="text" wicket:id="dateProperty" id="dateProperty" /> + <input wicket:id="doubleProperty" id="doubleProperty" type="text" size="40"/> <label>ListView</label> <ul> Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.java (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInput.java Mon Jul 2 12:40:35 2007 @@ -19,12 +19,10 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; -import java.util.Date; import java.util.List; import java.util.Locale; import org.apache.wicket.examples.WicketExamplePage; -import org.apache.wicket.extensions.yui.calendar.DatePicker; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.Check; @@ -95,9 +93,6 @@ RequiredTextField integerTextField = new RequiredTextField("integerProperty"); add(integerTextField.add(NumberValidator.POSITIVE)); add(new RequiredTextField("doubleProperty")); - - // add(new DateTimeField("dateProperty")); - add(new TextField("dateProperty", Date.class).add(new DatePicker())); add(new RequiredTextField("integerInRangeProperty").add(NumberValidator.range(0, 100))); add(new CheckBox("booleanProperty")); Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInputModel.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInputModel.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInputModel.java (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/FormInputModel.java Mon Jul 2 12:40:35 2007 @@ -83,7 +83,6 @@ } private Boolean booleanProperty; - private Date dateProperty = new Date(); private Double doubleProperty = new Double(20.5); private Integer integerInRangeProperty = new Integer(50); private Integer integerProperty = new Integer(100); @@ -127,16 +126,6 @@ } /** - * Gets dateProperty. - * - * @return dateProperty - */ - public Date getDateProperty() - { - return dateProperty; - } - - /** * Gets doubleProperty. * * @return doubleProperty @@ -260,17 +249,6 @@ } /** - * Sets dateProperty. - * - * @param dateProperty - * dateProperty - */ - public void setDateProperty(Date dateProperty) - { - this.dateProperty = dateProperty; - } - - /** * Sets doubleProperty. * * @param doubleProperty @@ -395,9 +373,8 @@ StringBuffer b = new StringBuffer(); b.append("[TestInputObject stringProperty = '").append(stringProperty).append( "', integerProperty = ").append(integerProperty).append(", doubleProperty = ") - .append(doubleProperty).append(", dateProperty = ").append(dateProperty).append( - ", booleanProperty = ").append(booleanProperty).append( - ", integerInRangeProperty = ").append(integerInRangeProperty).append( + .append(doubleProperty).append(", booleanProperty = ").append(booleanProperty) + .append(", integerInRangeProperty = ").append(integerInRangeProperty).append( ", urlProperty = ").append(urlProperty).append(", phoneNumberUS = ") .append(phoneNumberUS).append(", numberRadioChoice = ").append(numberRadioChoice) .append(", numbersCheckgroup ").append(numbersCheckGroup).append( Modified: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/Multiply.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/Multiply.java?view=diff&rev=552572&r1=552571&r2=552572 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/Multiply.java (original) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/forminput/Multiply.java Mon Jul 2 12:40:35 2007 @@ -104,17 +104,17 @@ } /** - * @see org.apache.wicket.markup.html.form.FormComponent#getConvertedInput() + * @see org.apache.wicket.markup.html.form.FormComponent#convertInput() */ @Override - public Object getConvertedInput() + protected void convertInput() { // note that earlier versions did override updateModel, which looked // somewhat better, but wasn't useful for when you want to do // validations with either normal validators or form validators Integer lhs = (Integer)left.getConvertedInput(); Integer rhs = (Integer)right.getConvertedInput(); - return lhs * rhs; + setConvertedInput(lhs * rhs); } private void init()