Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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;
 
 
Abstract base class for TextArea and TextField.

Parameters:
<T> The model object type
Author(s):
Jonathan Locke
 
 public abstract class AbstractTextComponent<T> extends FormComponent<T>
 {
 	// Flag for the type resolving. FLAG_RESERVED1-3 is taken by form component
 	private static final int TYPE_RESOLVED = .;

Log for reporting.
 
 	private static final Logger log = LoggerFactory.getLogger(AbstractTextComponent.class);

 
 	private static final long serialVersionUID = 1L;

Text components that implement this interface are know to be able to provide a pattern for formatting output and parsing input. This can be used by for instance date picker components which are based on Javascript and need some knowledge as to how to communicate properly via request parameters.
 
 	public static interface ITextFormatProvider
 	{
Gets the pattern for printing output and parsing input.

Returns:
The text pattern
See also:
java.text.SimpleDateFormat
 
 	}

See also:
org.apache.wicket.Component.org.apache.wicket.Component.(java.lang.String)
 
 	{
 		super(id);
 	}

Parameters:
id
model
See also:
org.apache.wicket.Component.org.apache.wicket.Component.(java.lang.String,org.apache.wicket.model.IModel)
 
 	public AbstractTextComponent(final String idfinal IModel<T> model)
 	{
 		super(idmodel);
 	}

Should the bound object become null when the input is empty?

Returns:
true when the value will be set to null when the input is empty.
 
 	public final boolean getConvertEmptyInputStringToNull()
 	{
 	}

TextFields return an empty string even if the user didn't type anything in them. To be able to work nicely with validation, this method returns false.

	public boolean isInputNullable()
	{
		return false;
	}

	protected void convertInput()
	{
		// Stateless forms don't have to be rendered first, convertInput could be called before
		// onBeforeRender calling resolve type here again to check if the type is correctly set.
		super.convertInput();
	}

If the type is not set try to guess it if the model supports it.

	protected void onBeforeRender()
	{
	}

	private void resolveType()
	{
		if (!getFlag() && getType() == null)
		{
			// Set the type, but only if it's not a String (see WICKET-606).
			// Otherwise, getConvertEmptyInputStringToNull() won't work.
			if (!String.class.equals(type))
			{
				setType(type);
			}
		}
	}

Parameters:
model
Returns:
the type of the model object or null
	private Class<?> getModelType(IModel<?> model)
	{
		if (model instanceof IObjectClassAwareModel)
		{
			Class<?> objectClass = ((IObjectClassAwareModel<?>)model).getObjectClass();
			if (objectClass == null)
			{
				.warn("Couldn't resolve model type of " + model + " for " + this +
					", please set the type yourself.");
			}
			return objectClass;
		}
		else
		{
			return null;
		}
	}

Should the bound object become null when the input is empty?

Parameters:
flag the value to set this flag.
Returns:
this
	public final FormComponent<T> setConvertEmptyInputStringToNull(boolean flag)
	{
		return this;
	}

	protected T convertValue(String[] valuethrows ConversionException
	{
		String tmp = value != null && value.length > 0 ? value[0] : null;
		if (getConvertEmptyInputStringToNull() && Strings.isEmpty(tmp))
		{
			return null;
		}
		return super.convertValue(value);
	}

	protected boolean supportsPersistence()
	{
		return true;
	}
New to GrepCode? Check out our FAQ X