mardi 30 décembre 2014

Thymeleaf + Spring Checkboxes not binding

Here's my snippets of code:


Vehicle Class:



// Duplicates
private Boolean regCard = true;
private Boolean decal;
private Boolean title;

public Boolean getRegCard() {
return regCard;
}

public void setRegCard(Boolean regCard) {
this.regCard = regCard;
}

public Boolean getDecal() {
return decal;
}

public void setDecal(Boolean decal) {
this.decal = decal;
}

public Boolean getTitle() {
return title;
}

public void setTitle(Boolean title) {
this.title = title;
}


Thymeleaf:



<form method="post" th:action="${flowExecutionUrl}" th:object="${customerModel.vehicle}">
<div class="duplicates">
<ul>
<li><label>What do you need to duplicate?</label>
<div class="regTitle">
<label>Registration Card
<input type="checkbox" th:field="*{regCard}"/>
</label>
<label>Decal
<input type="checkbox" th:field="*{decal}"/>
</label>
<div th:switch="*{vehicleType}">
<div th:case="'BR'">
<label>Title
<input th:type="checkbox" th:field="*{title}"/>
</label>
</div>
</div>
</div>
</li>
</ul>
<div class="clear"></div>
</div>
<div class="btm-btn-row">
<div class="btm-btn-left">
<a th:href="@{'~' + ${flowExecutionUrl}(_eventId='back')}">back</a>
</div>
<div class="btm-btn-right">
<input type="submit" value="continue" name="_eventId_continue" />
</div>
</div>
</form>


Generated HTML:



<form method="post" action="/IllinoisRVSWeb/main-flow?execution=e1s4">
<div class="duplicates">
<ul>
<li><label>What do you need to duplicate?</label>
<div class="regTitle">
<label>Registration Card
<input type="checkbox" id="vehicle.regCard1" name="vehicle.regCard" value="true" checked="checked" /><input type="hidden" name="_vehicle.regCard" value="on" />
</label>
<label>Decal
<input type="checkbox" id="vehicle.decal1" name="vehicle.decal" value="true" /><input type="hidden" name="_vehicle.decal" value="on" />
</label>
<div>
<div>
<label>Title
<input type="checkbox" id="vehicle.title1" name="vehicle.title" value="true" /><input type="hidden" name="_vehicle.title" value="on" />
</label>
</div>
</div>
</div>
</li>
</ul>
<div class="clear"></div>
</div>
<div class="btm-btn-row">
<div class="btm-btn-left">
<a href="/IllinoisRVSWeb/main-flow?execution=e1s4&amp;_eventId=back">back</a>
</div>
<div class="btm-btn-right">
<input type="submit" value="continue" name="_eventId_continue" />
</div>
</div>
</form>


Problem:


The boolean values never get set upon submit. I've tried the other way. Using a List object and binding that variable to the checkboxes with the proper th:value="'SOMETEXT'" for each checkbox. But that object stays null as well.


As you see I set one value to true beforehand to see if it would show up on the html side. It was successful. so its at least retrieving the value, but its not setting it if its ever changed.


Also, as you can see, I tried using "th:value="checkbox"" to see if that helped. It did not.


Thymeleaf Version 2.1.4


Spring 4.1.4


Spring WebFlow 2.4.0


Any help or tips would be great.


Thanks





Aucun commentaire:

Enregistrer un commentaire