CheckBox.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.web.lib.mvc.dynamic.components;

  21. import org.openspcoop2.monitor.engine.dynamic.IDynamicLoader;
  22. import org.openspcoop2.monitor.sdk.exceptions.ParameterException;
  23. import org.openspcoop2.monitor.sdk.parameters.Parameter;
  24. import org.openspcoop2.web.lib.mvc.Costanti;
  25. import org.openspcoop2.web.lib.mvc.DataElement;
  26. import org.openspcoop2.web.lib.mvc.DataElementType;
  27. import org.openspcoop2.web.lib.mvc.ServletUtils;

  28. /**
  29.  * CheckBox
  30.  *
  31.  * @author Pintori Giuliano (pintori@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  *
  35.  */
  36. public class CheckBox extends BaseComponent<Boolean> {

  37.     public CheckBox(Parameter<Boolean> parameter, IDynamicLoader loader) {
  38.         super(parameter, loader);
  39.     }

  40.     @Override
  41.     public DataElement toDataElement() throws ParameterException {
  42.         DataElement de = new DataElement();
  43.         de.setName(this.getId());
  44.         de.setLabel(this.getRendering().getLabel());
  45.         de.setLabelRight(this.getRendering().getLabelRight());
  46.         de.setPostBack_viaPOST(this.getRefreshParamIds().size() > 0);
  47.         de.setRequired(this.getRendering().isRequired());
  48.         de.setNote(this.getRendering().getSuggestion());
  49.         de.setType(DataElementType.CHECKBOX);
  50.         de.setValue(this.getValue() ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED );
  51.         de.setSelected(this.getValue() ? Costanti.CHECK_BOX_ENABLED : Costanti.CHECK_BOX_DISABLED );

  52.         return de;
  53.     }
  54.    
  55.     @Override
  56.     public void setValueFromRequest(String parameterValue) throws ParameterException {
  57.         if(parameterValue == null) {
  58.             if(this.getRendering().getDefaultValue()) {
  59.                 this.setValue(this.getRendering().getDefaultValue());
  60.             }
  61.             else {
  62.                 this.setValue(null);
  63.             }
  64.         }else {
  65.             this.setValue(ServletUtils.isCheckBoxEnabled(parameterValue));
  66.         }
  67.     }
  68. }