vendredi 24 juillet 2020

Spring MVC JSTL inputCheckbox does not allow to check or uncheck the checkbox

I have a form which requires the checkbox values to be submitted Checkboxes display correct data from database but would not be editable (check -> unchecked or unchecked -> check)

modelAttribute : Class CollegeCmd (contains list of College Object)

Form Backing Object

public class CollegeCmd {

    private List<College> collegeList;

    public CollegeListCmd() {
        // initialize collegeList with six colleges
        collegeList = ...
    }

    public List<College> getCollegeList() {
        return collegeList;
    }

    public void setCollegeList(List<College> collegeList) {
        this.collegeList = collegeList;
    }
}

Domain Object

public class College {

    
    private String name;
    private boolean availability;

    public boolean getAvailability() {
        return availability;
    }

    public String getName() {
        return name;
    }

    public void setAvailability(boolean availability) {
        this.availability= availability;
    }

    public void setName(String name) {
        this.name = name;
    }

The JSP Form

*jsp mentioned is the taglib name
<jsp:formAjax modelAttribute="collegeListCmd" actionUrl="/college/save-college-list" onSuccess="Saved" id="collegeForm" layout="vertical">
  <div class="container" id="configuration">
     <div class="row" id="collegeRowId">
       <div class="col-sm-12" id="collegeCheckboxesContainer">
          <div class="form-group" id="collegeCheckboxes">
             <label for="exampleFormControlSelect1">Included Colleges</label><br>
                <c:forEach items="${collegeCmd.collegeList}"  var="i"  varStatus="vs">
                    <jsp:inputCheckbox id="collegeList[${vs.index}].availability"  label="${i.name}" path="collegeList[${vs.index}].availability" />
                 </c:forEach>
           </div>
        </div>
     </div>
 </div>
                                
    <div class="field">
    <div class="input"><input type="submit" class="button primary"
        value="Save" />
    </div>
    </div>

</jsp:formAjax>

I found a link that says checkboxes dont work with Spring MVC JSTL but it didnt work for me [1]: https://github.com/flatlogic/awesome-bootstrap-checkbox/issues/14




Aucun commentaire:

Enregistrer un commentaire