Usage of check on a form with Short attribute instead of boolean

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Usage of check on a form with Short attribute instead of boolean

Hi, here a newbie .
<form id="pais-form">
        <p><input type="hidden" id="pais-id" /></p>
        <p>Nombre: <input type="text" id="pais-nombre" /></p>
        <p>Activo: <input type="checkbox" name="Activo" th:checked="${activo}"/></p>
        <p><input type="submit" value="Confirmar"></p>

Note that the attribute for "activo" is a Short and cannot change the ddl .
@Table(name = "PAIS")
public class Pais implements {
        private static final long serialVersionUID = 1L;
        private Long id;
        private String nombre;
        private Long idcapital;
        private Short activo; /* values: active=1 and inactive=0 */

When opening the form, the check is correctly checked/unchecked, but when click "submit" button I get :

Validation failed for object='pais'. Error count: 1
org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'pais' on field 'Activo': rejected value [on]; codes [typeMismatch.pais.Activo,typeMismatch.Activo,,typeMismatch]; arguments
[Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Short' for property 'Activo'; nested exception is java.lang.NumberFormatException: For input string: "on"]
I cannot guess how to convert the "on" value to 1 .
Also if I don't check it I have a JPA error on having a null value....