InputText.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.apache.commons.lang.StringUtils;
  22. import org.openspcoop2.monitor.engine.dynamic.IDynamicLoader;
  23. import org.openspcoop2.monitor.sdk.exceptions.ParameterException;
  24. import org.openspcoop2.monitor.sdk.parameters.Parameter;
  25. import org.openspcoop2.web.lib.mvc.DataElement;
  26. import org.openspcoop2.web.lib.mvc.DataElementType;

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

  36.     public InputText(Parameter<String> parameter,IDynamicLoader loader) {
  37.         super(parameter,loader);
  38.     }

  39.     @Override
  40.     public DataElement toDataElement() throws ParameterException {
  41.         DataElement de = new DataElement();
  42.         de.setName(this.getId());
  43.         de.setLabel(this.getRendering().getLabel());
  44.         de.setPostBack_viaPOST(this.getRefreshParamIds().size() > 0);
  45.         de.setRequired(this.getRendering().isRequired());
  46.         de.setNote(this.getRendering().getSuggestion());
  47.         de.setValue(this.getValue());
  48.         de.setType(DataElementType.TEXT_EDIT);

  49.         return de;
  50.     }
  51.    
  52.     @Override
  53.     public void setValueFromRequest(String parameterValue) throws ParameterException {
  54.         if(parameterValue == null) {
  55.             if(StringUtils.isNotEmpty(this.getRendering().getDefaultValue())) {
  56.                 this.setValue(this.getRendering().getDefaultValue());
  57.             }
  58.             else {
  59.                 this.setValue(null);
  60.             }
  61.         }else {
  62.             this.setValue(parameterValue);
  63.         }
  64.     }
  65. }