我在Spring MVC中遇到了一個問題。選擇表單中的內容並提交表單可以很好地工作,爲非布爾值選擇默認值也可以,但我有問題爲布爾值選擇默認值。在SpringMVC中<form:select>中選擇默認布爾值
我的JSP文件看起來是這樣的:
<form:form commandName="filterData" id="user_filter_form" action="${listUrl}" method="POST">
<form:label path="active">Active</form:label><br/>
<form:select path="active">
<option value="">--</option>
<option value="true">Yes</option>
<option value="false">No</option>
</form:select>
<form:label path="email">E-mail</form:label><br/>
<form:input path="email" type="search"/>
<button class="b not-ui" type="submit" style="margin-right: 25px">Search</button>
</form:form>
Model對象是這樣的:
public class UserFilterData {
private Boolean active;
private String email;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
}
正如我所說的,提交的作品很好,但是當我創建控制器這樣的,「電子郵件「字段中填入」[email protected]「,但選擇框已選擇第一個選項」---「
@RequestMapping(value = "/filter")
public String filterAction(Model model) {
UserFilterData data = new UserFilterData();
data.setEmail("[email protected]");
data.setActive(Boolean.TRUE);
model.addAttribute("filterData", data);
return "users/index;
}
I al所以嘗試在我的jsp中將「true」更改爲$ {true}或TRUE或1,但沒有任何成功。如果我使用${filterData.active}
在jsp中回顯filterData,結果爲true
,但未選擇適當的選項。有沒有人有一個想法我做錯了什麼?
我一定是失明的,我一直在和我的同事一起看,我們都沒有注意到。謝謝! – Kejml