0

我的视图模型有一个包含三个可能值的枚举:

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 进行操作的线程,但我没有使用它。有一个简单的解决方案吗?

4

1 回答 1

1

尝试这个,

<input type="radio" <c:if test="${model.thing eq 'Thing1'}">checked</c:if> name="thing" value="thing1" /> Thing1<br />
<input type="radio" <c:if test="${model.thing eq 'Thing2'}">checked</c:if> name="thing" value="thing2" /> Thing2<br />
<input type="radio" <c:if test="${model.thing eq 'Thing3'}">checked</c:if> name="thing" value="thing3" /> Thing3
于 2012-09-05T03:02:50.127 回答