jeudi 8 mars 2018

Spring MVC: JSP Checkbox value is not safed in the model

I have two different checkboxes:

<form:checkbox path="differentLanguage" id="isDifferentLanguage"></form:checkbox>


<form:checkbox path="onlyCompareNumbers" id="onlyCompareNumbers"></form:checkbox>

This is the part of my model:

private boolean         differentLanguage;
private boolean         onlyCompareNumbers;

public boolean isDifferentLanguage() {
    return differentLanguage;
}

public void setDifferentLanguage(boolean isDifferentLanguage) {
    this.differentLanguage = isDifferentLanguage;
}

public boolean isOnlyCompareNumbers() {
    return onlyCompareNumbers;
}

public void setOnlyCompareNumbers(boolean onlyCompareNumbers) {
    this.onlyCompareNumbers = onlyCompareNumbers;
}

I have the following problem: If someone checks the differentLanguage checkbox the onlyCompareNumber checkbox is also checked with the following snippet:

    $('#isDifferentLanguage').on('change', function() {
    if ($(this).prop('checked')) {
        $('#onlyCompareNumbers').prop('checked', true);
        $("#onlyCompareNumbers").attr("disabled", true);
    }else{
        $("#onlyCompareNumbers").attr("disabled", false);
    }
});

The checkbox onlyCompareNumber is checked in the view. Nevertheless, the boolean is false. I don't know how to address the "path =onlyCompareNumbers" within my snippet. I think this is the problem.

Just to let you know: If I check the onlyCompareNumbers checkbox everything works well and the boolean is set to true!!




Aucun commentaire:

Enregistrer un commentaire