mercredi 6 février 2019

Checkbox in JHipster

I have a checkbox in the html

<input type="checkbox" class="form-control" name="myflag" [(ngModel)]="myEntity.myflag" id="field_myflag">

The field (myflag) on DB has 2 possible value [OK, KO] and these 2 values are defined in an enumeration:

@Enumerated(EnumType.STRING)
@Column(name = "MYFLAG")
private MYFLAGENUM myflag;

so:

public enum MYFLAGENUM {
   OK, KO
}

Every time I try to save, I reach an exception:

WARN 888 --- [ XNIO-7 task-5] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of myproject.hipster.testing.domain.enumeration.MYFLAGENUM out of VALUE_FALSE token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of myproject.hipster.testing.domain.enumeration.MYFLAGENUM out of VALUE_FALSE token at [Source: (PushbackInputStream); line: 1, column: 37] (through reference chain: myproject.hipster.testing.domain.MYENTITY["myflag"])

It seems VALUE_FALSE (or VALUE_TRUE) could not be converted to 'KO' (or 'OK'). So I create a converter, but I see it is not called. How can I manage my own "boolean" value with JHipster checkbox?




Aucun commentaire:

Enregistrer un commentaire