Changeset 5021
- Timestamp:
- 07/03/08 10:27:53 (6 months ago)
- Location:
- trunk/src/com/itmill/toolkit/ui
- Files:
-
- 3 modified
-
AbstractField.java (modified) (5 diffs)
-
Field.java (modified) (1 diff)
-
Form.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/itmill/toolkit/ui/AbstractField.java
r4874 r5021 110 110 */ 111 111 private boolean required = false; 112 113 /** 114 * The error message for the exception that is thrown when the field is 115 * required but empty. 116 */ 117 private String requiredError = ""; 112 118 113 119 /** … … 611 617 return true; 612 618 } 613 614 /** 615 * Checks the validity of the validatable 619 620 public class EmptyValueException extends Validator.InvalidValueException { 621 /** 622 * Serial generated by eclipse. 623 */ 624 private static final long serialVersionUID = -4488988853486652602L; 625 626 public EmptyValueException(String message) { 627 super(message); 628 } 629 630 } 631 632 /** 633 * Checks the validity of the Validatable by validating the field with all 634 * attached validators. 635 * 636 * The "required" validation is a built-in validation feature. If the field 637 * is required, but empty, validation will throw an EmptyValueException 638 * with the error message set with setRequiredError(). 616 639 * 617 640 * @see com.itmill.toolkit.data.Validatable#validate() … … 621 644 if (isRequired()) { 622 645 if (isEmpty()) { 623 throw new Validator.InvalidValueException("");646 throw new EmptyValueException(requiredError); 624 647 } 625 648 } … … 716 739 ErrorMessage validationError = null; 717 740 if (isValidationVisible()) { 718 if (!(isRequired() && isEmpty())) { 719 try { 720 validate(); 721 } catch (Validator.InvalidValueException e) { 722 validationError = e; 723 } 741 try { 742 validate(); 743 } catch (Validator.InvalidValueException e) { 744 validationError = e; 724 745 } 725 746 } … … 1022 1043 requestRepaint(); 1023 1044 } 1045 1046 public void setRequiredError(String requiredMessage) { 1047 this.requiredError = requiredMessage; 1048 requestRepaint(); 1049 } 1050 1051 public String getRequiredError() { 1052 return requiredError; 1053 } 1024 1054 1025 1055 /** -
trunk/src/com/itmill/toolkit/ui/Field.java
r3162 r5021 54 54 55 55 /** 56 * Sets the error message to be displayed if a required field is empty. 57 * 58 * @param requiredMessage 59 * Error message. 60 * @since 5.2.6 61 */ 62 public void setRequiredError(String requiredMessage); 63 64 /** 65 * Gets the error message that is to be displayed if a required field is 66 * empty. 67 * 68 * @return Error message. 69 * @since 5.2.6 70 */ 71 public String getRequiredError(); 72 73 /** 56 74 * An <code>Event</code> object specifying the Field whose value has been 57 75 * changed. -
trunk/src/com/itmill/toolkit/ui/Form.java
r4860 r5021 18 18 import com.itmill.toolkit.data.Validator.InvalidValueException; 19 19 import com.itmill.toolkit.data.util.BeanItem; 20 import com.itmill.toolkit.terminal.ErrorMessage; 20 21 import com.itmill.toolkit.terminal.PaintException; 21 22 import com.itmill.toolkit.terminal.PaintTarget; … … 171 172 } 172 173 174 /** 175 * The error message of a Form is the error of the first field with a 176 * non-empty error. 177 * 178 * Empty error messages of the contained fields are skipped, because an 179 * empty error indicator would be confusing to the user, especially if there 180 * are errors that have something to display. This is also the reason why 181 * the calculation of the error message is separate from validation, because 182 * validation fails also on empty errors. 183 */ 184 @SuppressWarnings("unchecked") 185 @Override 186 public ErrorMessage getErrorMessage() { 187 for (final Iterator i = propertyIds.iterator(); i.hasNext();) { 188 try { 189 AbstractComponent field = (AbstractComponent)fields.get(i.next()); 190 ErrorMessage e = field.getErrorMessage(); 191 if (e != null) { 192 // Skip empty errors 193 if (e.toString().isEmpty()) 194 continue; 195 return e; 196 } 197 } catch (ClassCastException ignored) {} 198 } 199 return null; 200 } 201 173 202 /* 174 203 * Commit changes to the data source Don't add a JavaDoc comment here, we
