我的视图模型有一个包含三个可能值的枚举:
public enum PollFrequency {
SixHours, TwentyFourHours, Weekly
}
public class AlertViewModel {
private PollFrequency pollFrequency;
public PollFrequency getPollFrequency(){
return pollFrequency;
}
public void setPollFrequency(PollFrequency pollFrequency){
this.pollFrequency = pollFrequency;
}
public AlertViewModel(){
pollFrequency = PollFrequency.TwentyFourHours;
}
}
我的 JSP 页面有一组三个单选按钮:
<input checked="<c:if test="${viewModel.pollFrequency eq 'SixHours'}">checked</c:if>" type="radio" name="checkEvery" value="checkEvery6Hours" /> 6 Hours<br />
<input checked="<c:if test="${viewModel.pollFrequency eq 'TwentyFourHours'}">checked</c:if>" type="radio" name="checkEvery" value="checkEvery24Hours" /> 24 Hours<br />
<input checked="<c:if test="${viewModel.pollFrequency eq 'Weekly'}">checked</c:if>" type="radio" name="checkEvery" value="checkEveryWeek" /> Weekly
我想根据枚举值设置单选按钮的选中属性,但目前总是选中最后一个单选按钮。我发现了一些关于如何使用 springsource 进行操作的线程,但我没有使用它。有一个简单的解决方案吗?