alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (AbstractCheckedElementTag.java)

This example Spring Framework source code file (AbstractCheckedElementTag.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

abstractcheckedelementtag, abstractcheckedelementtag, abstracthtmlinputelementtag, bean, http, javabean, jspexception, jspexception, object, object, propertyeditor, servlet, string, tagwriter, tagwriter

The Spring Framework AbstractCheckedElementTag.java source code

/*
 * Copyright 2002-2008 the original author or authors.
 *
 * Licensed 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.springframework.web.servlet.tags.form;

import java.beans.PropertyEditor;

import javax.servlet.jsp.JspException;

/**
 * Abstract base class to provide common methods for
 * implementing databinding-aware JSP tags for rendering an HTML '<code>input'
 * element with a '<code>type' of 'checkbox' or 'radio'.
 *
 * @author Thomas Risberg
 * @author Juergen Hoeller
 * @since 2.5
 */
public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElementTag {

	/**
	 * Render the '<code>input(checkbox)' with the supplied value, marking the
	 * '<code>input' element as 'checked' if the supplied value matches the
	 * bound value.
	 */
	protected void renderFromValue(Object value, TagWriter tagWriter) throws JspException {
		renderFromValue(value, value, tagWriter);
	}

	/**
	 * Render the '<code>input(checkbox)' with the supplied value, marking the
	 * '<code>input' element as 'checked' if the supplied value matches the
	 * bound value.
	 */
	protected void renderFromValue(Object item, Object value, TagWriter tagWriter) throws JspException {
		PropertyEditor editor = (value != null ? getBindStatus().findEditor(value.getClass()) : null);
		tagWriter.writeAttribute("value", getDisplayString(value, editor));
		if (isOptionSelected(value) || (value != item && isOptionSelected(item))) {
			tagWriter.writeAttribute("checked", "checked");
		}
	}
	
	/**
	 * Determines whether the supplied value matched the selected value
	 * through delegating to {@link SelectedValueComparator#isSelected}.
	 */
	private boolean isOptionSelected(Object value) throws JspException {
		return SelectedValueComparator.isSelected(getBindStatus(), value);
	}

	/**
	 * Render the '<code>input(checkbox)' with the supplied value, marking
	 * the '<code>input' element as 'checked' if the supplied Boolean is
	 * <code>true.
	 */
	protected void renderFromBoolean(Boolean boundValue, TagWriter tagWriter) throws JspException {
		tagWriter.writeAttribute("value", "true");
		if (boundValue.booleanValue()) {
			tagWriter.writeAttribute("checked", "checked");
		}
	}

	/**
	 * Return a unique ID for the bound name within the current PageContext.
	 */
	protected String autogenerateId() throws JspException {
		return TagIdGenerator.nextId(getName(), this.pageContext);
	}


	/**
	 * Writes the '<code>input' element to the supplied
	 * {@link org.springframework.web.servlet.tags.form.TagWriter},
	 * marking it as 'checked' if appropriate.
	 */
	protected abstract int writeTagContent(TagWriter tagWriter) throws JspException;

}

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework AbstractCheckedElementTag.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.