Package de.odysseus.calyxo.forms.taglib.html

Source Code of de.odysseus.calyxo.forms.taglib.html.CheckboxTag

/*
* Copyright 2004, 2005, 2006 Odysseus Software GmbH
*
* 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 de.odysseus.calyxo.forms.taglib.html;

import de.odysseus.calyxo.base.conf.ConfigException;
import de.odysseus.calyxo.forms.view.DefaultGroupModel;
import de.odysseus.calyxo.forms.view.GroupComponent;
import de.odysseus.calyxo.forms.view.GroupModel;
/**
* HTML checkbox tag.
*
* @author Oliver Stuhr
*/
public class CheckboxTag extends RadioTag implements GroupComponent {

  /**
   * Default constructor
   */
  public CheckboxTag() {
    super("checkbox");
  }

  /* (non-Javadoc)
   * @see de.odysseus.calyxo.forms.view.GroupComponent#isSelectable(java.lang.String)
   */
  public boolean isSelectable(String value) {
    return value != null;
  }

  protected void checkMultiple() throws Exception {
    if (getContext().isMultiple(this)) {
      if (getValue() == null) {
        throw new ConfigException("An array checkbox requires a value!");
      }
    }
  }

  /**
   * Get checked attribute
   */
  protected String getCheckedAttribute() throws Exception {
    if (getContext().isMultiple(this)) {
      GroupModel group = (GroupModel)getContext().getComponentData(this);
      if (group == null) {
        group = new DefaultGroupModel(getContext(), this);
        getContext().putComponentData(this, group);
      }
      if (group.isSelected(getValue())) {
        return "checked";
      } else if (!group.isSelectionAvailable() && getChecked() != null) {
        return "checked";
      }
      return null;
    } else {
      return super.getCheckedAttribute();
    }
  }

  /**
   * Get value attribute
   */
  protected String getValueAttribute() throws Exception {
    return getValue() == null ? "true" : super.getValueAttribute();
  }
}
TOP

Related Classes of de.odysseus.calyxo.forms.taglib.html.CheckboxTag

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.