在我的Spring Webflow(使用JSP视图)中,我有一个包含其中一个字段的枚举的模型。我需要一个带有一组单选按钮的表单,其中只包含几个可能的枚举值,我似乎无法破解如何操作。
所以我的流程是这样的:
<on-start>
<evaluate expression="someService.getModel()" result="flowScope.myModel" />
</on-start>
<view-state id="step1" view="step1View" model="myModel">
<transition on="proceed" to="step2"/>
</view-state>
myModel有一个名为&#34; paymentType&#34;这是一个枚举(称为PaymentType),看起来像这样:
public enum PaymentType{
RE("A paper reciept"),
CC("Credit Card"),
PA("Pre-Authorised Debit"),
MC("MyCoin"),
private final String shortDescription;
PaymentOptionType(final String shortDescription) {
this.shortDescription = shortDescription;
}
public String getShortDescription() {
return shortDescription;
}
}
所以,让我们在我的step1页面中说我只想在表单中放入其中的2个值。 所以它看起来像:
* A paper reciept
* MyCoin
|Submit|
它会将所选值绑定到模型中的paymentType字段。
所以我想知道如何在step1.jsp中填充表单中的单选按钮
<form:form id="paymentForm" name="paymentForm" modelAttribute="myModel" method="post" action="${flowExecutionUrl}">
<!-- What to put for radio buttons here? -->
<button name="_eventId_proceed">Next Step</button>
</form:form>
答案 0 :(得分:1)
尝试:
<form:radiobutton path="paymentType" value="RE"/>A paper receipt
<form:radiobutton path="paymentType" value="MC"/>My Coin
..
或在您的流程中添加类似的内容
<on-start>
<evaluate expression="someService.getPaymentTypes()" result="flowScope.paymentTypes" />
</on-start>
然后使用
<c:forEach var="paymentType" items="${paymentTypes}>
<form:radiobutton path="paymentType" value="${paymentType}"/>${paymentType.shortDescription}
</c:forEach>