You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by al...@apache.org on 2007/06/18 05:58:59 UTC

svn commit: r548197 - /incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/

Author: almaw
Date: Sun Jun 17 20:58:58 2007
New Revision: 548197

URL: http://svn.apache.org/viewvc?view=rev&rev=548197
Log:
WICKET-531 - Form component labels for Radio/Check.

Added:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/ILabelProvider.java   (with props)
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/LabeledWebMarkupContainer.java   (with props)
Modified:
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Check.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/FormComponentLabel.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Radio.java
    incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/SimpleFormComponentLabel.java

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Check.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Check.java?view=diff&rev=548197&r1=548196&r2=548197
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Check.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Check.java Sun Jun 17 20:58:58 2007
@@ -36,11 +36,8 @@
  * @author Igor Vaynberg (ivaynberg@users.sf.net)
  * 
  */
-public class Check extends WebMarkupContainer
+public class Check extends LabeledWebMarkupContainer
 {
-	/**
-	 * 
-	 */
 	private static final long serialVersionUID = 1L;
 
 	private static final String ATTR_DISABLED = "disabled";

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=548197&r1=548196&r2=548197
==============================================================================
--- 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 Sun Jun 17 20:58:58 2007
@@ -32,8 +32,6 @@
 import org.apache.wicket.Page;
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.model.IComponentAssignedModel;
 import org.apache.wicket.model.IModel;
 import org.apache.wicket.util.convert.ConversionException;
 import org.apache.wicket.util.convert.IConverter;
@@ -42,11 +40,11 @@
 import org.apache.wicket.util.string.StringList;
 import org.apache.wicket.util.string.Strings;
 import org.apache.wicket.util.string.interpolator.MapVariableInterpolator;
-import org.apache.wicket.validation.IValidatorAddListener;
 import org.apache.wicket.validation.IErrorMessageSource;
 import org.apache.wicket.validation.IValidatable;
 import org.apache.wicket.validation.IValidationError;
 import org.apache.wicket.validation.IValidator;
+import org.apache.wicket.validation.IValidatorAddListener;
 import org.apache.wicket.validation.ValidationError;
 import org.apache.wicket.version.undo.Change;
 
@@ -75,7 +73,7 @@
  * @author Johan Compagner
  * @author Igor Vaynberg (ivaynberg)
  */
-public abstract class FormComponent extends WebMarkupContainer implements IFormVisitorParticipant
+public abstract class FormComponent extends LabeledWebMarkupContainer implements IFormVisitorParticipant
 {
 	/**
 	 * Visitor for traversing form components
@@ -406,12 +404,6 @@
 	private transient Object convertedInput;
 
 	/**
-	 * The value will be made available to the validator property by means of
-	 * ${label}. It does not have any specific meaning to FormComponent itself.
-	 */
-	private IModel labelModel = null;
-
-	/**
 	 * Raw Input entered by the user or NO_RAW_INPUT if nothing is filled in.
 	 */
 	private String rawInput = NO_RAW_INPUT;
@@ -419,7 +411,7 @@
 	/**
 	 * Type that the raw input string will be converted to
 	 */
-	private Class type;
+	private String typeName;
 
 	/**
 	 * The list of validators for this form component as either an IValidator
@@ -650,18 +642,6 @@
 		return inputName.toString();
 	}
 
-
-	/**
-	 * The value will be made available to the validator property by means of
-	 * ${label}. It does not have any specific meaning to FormComponent itself.
-	 * 
-	 * @return labelModel
-	 */
-	public IModel getLabel()
-	{
-		return this.labelModel;
-	}
-
 	/**
 	 * Use hasRawInput() to check if this component has raw input because null
 	 * can mean 2 things: It doesn't have rawinput or the rawinput is really
@@ -679,7 +659,7 @@
 	 */
 	public final Class getType()
 	{
-		return type;
+		return typeName == null ? null : Classes.resolveClass(typeName);
 	}
 
 	/**
@@ -890,23 +870,6 @@
 	}
 
 	/**
-	 * The value will be made available to the validator property by means of
-	 * ${label}. It does not have any specific meaning to FormComponent itself.
-	 * 
-	 * @param labelModel
-	 * @return this for chaining
-	 */
-	public FormComponent setLabel(IModel labelModel)
-	{
-		if (labelModel instanceof IComponentAssignedModel)
-		{
-			labelModel = ((IComponentAssignedModel)labelModel).wrapOnAssignment(this);
-		}
-		this.labelModel = labelModel;
-		return this;
-	}
-
-	/**
 	 * Sets the value for a form component this value will be split the string
 	 * with {@link FormComponent#VALUE_SEPARATOR} and calls
 	 * setModelValue(String[]) with that.
@@ -962,7 +925,7 @@
 	 */
 	public final FormComponent setRequired(final boolean required)
 	{
-		if (!required && type != null && type.isPrimitive())
+		if (!required && getType() != null && getType().isPrimitive())
 		{
 			throw new WicketRuntimeException(
 					"FormComponent can't be not required when the type is primitive class: " + this);
@@ -984,9 +947,11 @@
 	 */
 	public final FormComponent setType(Class type)
 	{
-		this.type = type;
+		this.typeName = type == null ? null : type.getName();
 		if (type != null && type.isPrimitive())
+		{
 			setRequired(true);
+		}
 		return this;
 	}
 
@@ -1117,7 +1082,7 @@
 	 */
 	protected final void convert()
 	{
-		if (type == null)
+		if (typeName == null)
 		{
 			try
 			{
@@ -1153,7 +1118,7 @@
 		}
 		else
 		{
-			final IConverter converter = getConverter(type);
+			final IConverter converter = getConverter(getType());
 			try
 			{
 				convertedInput = converter.convertToObject(getInput(), getLocale());
@@ -1165,11 +1130,12 @@
 				{
 					error.addMessageKey(e.getResourceKey());
 				}
-				error.addMessageKey("IConverter." + Classes.simpleName(type));
+				String simpleName = Classes.simpleName(getType());
+				error.addMessageKey("IConverter." + simpleName);
 				error.addMessageKey("IConverter");
 
 
-				error.setVariable("type", Classes.simpleName(type));
+				error.setVariable("type", simpleName);
 				final Locale locale = e.getLocale();
 				if (locale != null)
 				{

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponentLabel.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponentLabel.java?view=diff&rev=548197&r1=548196&r2=548197
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponentLabel.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/FormComponentLabel.java Sun Jun 17 20:58:58 2007
@@ -16,14 +16,13 @@
  */
 package org.apache.wicket.markup.html.form;
 
-import org.apache.wicket.Component;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 
 /**
- * A component that represents html label tag. This component will automatically
- * make the form component output an id attribute and link its for attribute
- * with that value.
+ * A component that represents html <label> tag. This component will
+ * automatically make the form component output an id attribute and link its for
+ * attribute with that value.
  * 
  * @author Igor Vaynberg (ivaynberg)
  */
@@ -31,48 +30,17 @@
 {
 	private static final long serialVersionUID = 1L;
 
-	private Component component;
+	private LabeledWebMarkupContainer component;
 
 	/**
 	 * Constructor
 	 * 
 	 * @param id
 	 *            component id
-	 * @param check
-	 *            Check component that this label represents
+	 * @param component
+	 *            component that this label is linked to
 	 */
-	public FormComponentLabel(String id, Check check)
-	{
-		this(id, (Component)check);
-	}
-	
-	/**
-	 * Constructor
-	 * 
-	 * @param id
-	 *            component id
-	 * @param radio
-	 *            Radio component that this label represents
-	 */
-	public FormComponentLabel(String id, Radio radio)
-	{
-		this(id, (Component)radio);
-	}
-
-	/**
-	 * Constructor
-	 * 
-	 * @param id
-	 *            component id
-	 * @param formComponent
-	 *            FormComponent that this label represents
-	 */
-	public FormComponentLabel(String id, FormComponent formComponent)
-	{
-		this(id, (Component)formComponent);
-	}
-	
-	private FormComponentLabel(String id, Component component)
+	public FormComponentLabel(String id, LabeledWebMarkupContainer component)
 	{
 		super(id);
 		if (component == null)
@@ -92,12 +60,12 @@
 
 
 	/**
-	 * Returns form component bound to this label.
-	 * This will be a FormComponent, a Radio or a Check.
+	 * Returns LabeledWebMarkupContainer bound to this label. This will be a
+	 * FormComponent, a Radio or a Check.
 	 * 
 	 * @return form component
 	 */
-	public Component getFormComponent()
+	public LabeledWebMarkupContainer getFormComponent()
 	{
 		return component;
 	}

Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/ILabelProvider.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/ILabelProvider.java?view=auto&rev=548197
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/ILabelProvider.java (added)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/ILabelProvider.java Sun Jun 17 20:58:58 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.markup.html.form;
+
+import org.apache.wicket.model.IModel;
+
+/**
+ * Provider of labels for FormComponents and others.
+ * 
+ * @author almaw
+ */
+public interface ILabelProvider
+{
+	/**
+	 * The value will be made available to the validator property by means of
+	 * ${label}. It does not have any specific meaning to FormComponent itself.
+	 * 
+	 * @return labelModel
+	 */
+	public IModel getLabel();
+
+	/**
+	 * The value will be made available to the validator property by means of
+	 * ${label}. It does not have any specific meaning to FormComponent itself.
+	 * 
+	 * @param labelModel
+	 * @return this for chaining
+	 */
+	public ILabelProvider setLabel(IModel labelModel);
+}

Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/ILabelProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/LabeledWebMarkupContainer.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/LabeledWebMarkupContainer.java?view=auto&rev=548197
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/LabeledWebMarkupContainer.java (added)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/LabeledWebMarkupContainer.java Sun Jun 17 20:58:58 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.markup.html.form;
+
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.model.IComponentAssignedModel;
+import org.apache.wicket.model.IModel;
+
+/**
+ * Default implementation of {@link ILabelProvider}.
+ * 
+ * @author almaw
+ */
+public abstract class LabeledWebMarkupContainer extends WebMarkupContainer
+		implements
+			ILabelProvider
+{
+	/**
+	 * The value will be made available to the validator property by means
+	 * of ${label}. It does not have any specific meaning to FormComponent
+	 * itself.
+	 */
+	private IModel labelModel = null;
+
+	/**
+	 * @see org.apache.wicket.Component#Component(String)
+	 */
+	public LabeledWebMarkupContainer(final String id)
+	{
+		super(id);
+	}
+
+	/**
+	 * @see org.apache.wicket.Component#Component(String, IModel)
+	 */
+	public LabeledWebMarkupContainer(final String id, final IModel model)
+	{
+		super(id, model);
+	}
+
+	/**
+	 * @see org.apache.wicket.markup.html.form.ILabelProvider#getLabel()
+	 */
+	public IModel getLabel()
+	{
+		return labelModel;
+	}
+
+	/**
+	 * @see org.apache.wicket.markup.html.form.ILabelProvider#setLabel(org.apache.wicket.model.IModel)
+	 */
+	public ILabelProvider setLabel(IModel labelModel)
+	{
+		if (labelModel instanceof IComponentAssignedModel)
+		{
+			labelModel = ((IComponentAssignedModel)labelModel).wrapOnAssignment(this);
+		}
+		this.labelModel = labelModel;
+		return this;
+	}
+}

Propchange: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/LabeledWebMarkupContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Radio.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Radio.java?view=diff&rev=548197&r1=548196&r2=548197
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Radio.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/Radio.java Sun Jun 17 20:58:58 2007
@@ -35,14 +35,10 @@
  * @author Sven Meier (svenmeier)
  * 
  */
-public class Radio extends WebMarkupContainer
+public class Radio extends LabeledWebMarkupContainer
 {
-	private static final String ATTR_DISABLED = "disabled";
-	/**
-	 * 
-	 */
 	private static final long serialVersionUID = 1L;
-
+	private static final String ATTR_DISABLED = "disabled";
 
 	/**
 	 * page-scoped uuid of this check. this property must not be accessed

Modified: incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/SimpleFormComponentLabel.java
URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/SimpleFormComponentLabel.java?view=diff&rev=548197&r1=548196&r2=548197
==============================================================================
--- incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/SimpleFormComponentLabel.java (original)
+++ incubator/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/html/form/SimpleFormComponentLabel.java Sun Jun 17 20:58:58 2007
@@ -34,19 +34,19 @@
 	 * 
 	 * @param id
 	 *            component id
-	 * @param fc
-	 *            form component
+	 * @param labelProvider
+	 *            label provider (e.g. FormComponent, Radio, Check)
 	 */
-	public SimpleFormComponentLabel(String id, FormComponent fc)
+	public SimpleFormComponentLabel(String id, LabeledWebMarkupContainer labelProvider)
 	{
-		super(id, fc);
-		if (fc.getLabel() == null)
+		super(id, labelProvider);
+		if (labelProvider.getLabel() == null)
 		{
 			throw new IllegalStateException("Provided form component does not have a label set. "
 					+ "Use FormComponent.setLabel(IModel) to set the model "
 					+ "that will feed this label");
 		}
-		setModel(fc.getLabel());
+		setModel(labelProvider.getLabel());
 	}
 
 	/**