001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.servlet.tags.form; 018 019import javax.servlet.jsp.JspException; 020 021import org.springframework.web.bind.WebDataBinder; 022 023/** 024 * Databinding-aware JSP tag for rendering multiple HTML '{@code input}' 025 * elements with a '{@code type}' of '{@code checkbox}'. 026 * 027 * <p>Intended to be used with a Collection as the {@link #getItems()} bound value}. 028 * 029 * @author Thomas Risberg 030 * @author Juergen Hoeller 031 * @author Mark Fisher 032 * @since 2.5 033 */ 034@SuppressWarnings("serial") 035public class CheckboxesTag extends AbstractMultiCheckedElementTag { 036 037 @Override 038 protected int writeTagContent(TagWriter tagWriter) throws JspException { 039 super.writeTagContent(tagWriter); 040 041 if (!isDisabled()) { 042 // Write out the 'field was present' marker. 043 tagWriter.startTag("input"); 044 tagWriter.writeAttribute("type", "hidden"); 045 String name = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + getName(); 046 tagWriter.writeAttribute("name", name); 047 tagWriter.writeAttribute("value", processFieldValue(name, "on", "hidden")); 048 tagWriter.endTag(); 049 } 050 051 return SKIP_BODY; 052 } 053 054 @Override 055 protected String getInputType() { 056 return "checkbox"; 057 } 058 059}