My viewmodel has an enum with three possible values:
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;
}
}
My JSP page has a set of three radio buttons:
<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
I’d like to set the checked property of the radio buttons based on the enum value, but currently the last radio button is always checked. I found some threads on how to do it with springsource, but I’m not using that. Is there a simple solution to this?
Try this,