Funcionamiento de los checkboxs en Struts

2050 vistas

Los checkboxs tienen un funcionamiento particular. De hecho, un checkbox sólo devuelve el valor especificado en el atributo si éste está chequeado.



html4strict
  1. <html:checkbox property="someprop" value="true">Yes</html:checkbox>



En la action, recuperamos el valor haciendo:



java
  1. String somepropValue = null;
  2. if((somepropValue = request.getParameter("someprop")) != null)
  3. {
  4.   // ckecked
  5.   Sytem.out.println("The box is checked and its value is " + somepropValue);
  6. }
  7. else
  8. {
  9.   // not ckecked
  10.   Sytem.out.println("The box is not checked");
  11.   // set the value
  12.   someprop = "false";
  13. }



Si no está marcado, tendremos que darle explÃcitamente un valor (si fuera necesario).