You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2011/07/02 00:24:58 UTC
svn commit: r1142108 - in /wicket/trunk/wicket-core/src:
main/java/org/apache/wicket/markup/html/form/
main/java/org/apache/wicket/validation/
test/java/org/apache/wicket/validation/
Author: ivaynberg
Date: Fri Jul 1 22:24:58 2011
New Revision: 1142108
URL: http://svn.apache.org/viewvc?rev=1142108&view=rev
Log:
Issue: WICKET-3857
Added:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/validation/Validatable.java (with props)
Removed:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/validation/Validatable.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/validation/IValidatable.java
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java?rev=1142108&r1=1142107&r2=1142108&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/markup/html/form/FormComponent.java Fri Jul 1 22:24:58 2011
@@ -301,6 +301,11 @@ public abstract class FormComponent<T> e
{
return FormComponent.this.isValid();
}
+
+ public IModel<T> getModel()
+ {
+ return FormComponent.this.getModel();
+ }
}
/**
Modified: wicket/trunk/wicket-core/src/main/java/org/apache/wicket/validation/IValidatable.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/validation/IValidatable.java?rev=1142108&r1=1142107&r2=1142108&view=diff
==============================================================================
--- wicket/trunk/wicket-core/src/main/java/org/apache/wicket/validation/IValidatable.java (original)
+++ wicket/trunk/wicket-core/src/main/java/org/apache/wicket/validation/IValidatable.java Fri Jul 1 22:24:58 2011
@@ -16,6 +16,8 @@
*/
package org.apache.wicket.validation;
+import org.apache.wicket.model.IModel;
+
/**
* Interface representing any object that can be validated.
@@ -51,4 +53,11 @@ public interface IValidatable<T>
* @return <code>true</code> if the object is in a valid state, <code>false</code> if otherwise
*/
boolean isValid();
+
+ /**
+ * Returns the model of the component being validated
+ *
+ * @return component's model
+ */
+ IModel<T> getModel();
}
Added: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/validation/Validatable.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/validation/Validatable.java?rev=1142108&view=auto
==============================================================================
--- wicket/trunk/wicket-core/src/test/java/org/apache/wicket/validation/Validatable.java (added)
+++ wicket/trunk/wicket-core/src/test/java/org/apache/wicket/validation/Validatable.java Fri Jul 1 22:24:58 2011
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.validation;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.wicket.model.IModel;
+
+/**
+ * This implementation of {@link IValidatable} is meant to be used outside of Wicket. It allows
+ * other parts of the application to utilize {@link IValidator}s for validation.
+ * <p>
+ * Example: <code><pre>
+ * class WebService
+ * {
+ * public void addUser(String firstName, String lastName)
+ * {
+ * Validatable standin = new Validatable();
+ * standin.setValue(firstName);
+ * new FirstNameValidator().validate(standin);
+ * standing.setValue(lastName);
+ * new LastNameValidator().validate(standin);
+ * if (!standin.isValid())
+ * {
+ * // roll your own ValidationException
+ * throw new ValidationException(standin.getErrors());
+ * }
+ * else
+ * {
+ * // add user here
+ * }
+ * }
+ * }
+ * </pre></code>
+ *
+ * @author Igor Vaynberg (ivaynberg)
+ * @param <T>
+ * type of validatable
+ * @since 1.2.6
+ */
+public class Validatable<T> implements IValidatable<T>
+{
+ /** the value object */
+ private T value;
+
+ /** the list of errors */
+ private ArrayList<IValidationError> errors;
+
+ private IModel<T> model;
+
+ /**
+ * Constructor.
+ */
+ public Validatable()
+ {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param value
+ * The value that will be tested
+ */
+ public Validatable(T value)
+ {
+ this.value = value;
+ }
+
+ /**
+ * Sets model
+ *
+ * @param model
+ */
+ public void setModel(IModel<T> model)
+ {
+ this.model = model;
+ }
+
+ /**
+ * Sets the value object that will be returned by {@link #getValue()}.
+ *
+ * @param value
+ * the value object
+ */
+ public void setValue(T value)
+ {
+ this.value = value;
+ }
+
+ /**
+ * @see IValidatable#getValue()
+ */
+ public T getValue()
+ {
+ return value;
+ }
+
+ /**
+ * @see IValidatable#error(IValidationError)
+ */
+ public void error(IValidationError error)
+ {
+ if (errors == null)
+ {
+ errors = new ArrayList<IValidationError>();
+ }
+ errors.add(error);
+ }
+
+ /**
+ * Retrieves an unmodifiable list of any errors reported against this <code>IValidatable</code>
+ * instance.
+ *
+ * @return an unmodifiable list of errors
+ */
+ public List<IValidationError> getErrors()
+ {
+ if (errors == null)
+ {
+ return Collections.emptyList();
+ }
+ else
+ {
+ return Collections.unmodifiableList(errors);
+ }
+ }
+
+ /**
+ * @see IValidatable#isValid()
+ */
+ public boolean isValid()
+ {
+ return errors == null;
+ }
+
+ public IModel<T> getModel()
+ {
+ return null;
+ }
+
+}
Propchange: wicket/trunk/wicket-core/src/test/java/org/apache/wicket/validation/Validatable.java
------------------------------------------------------------------------------
svn:mime-type = text/plain