将单选按钮绑定到 Spring Webflow 中的特定枚举值
Binding radio buttons to specific enum values in Spring Webflow
在我的 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 有一个名为 "paymentType" 的字段,它是一个枚举(称为 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;
}
}
假设在我的第 1 步页面中,我只想将这些值中的 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>
尝试:
<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>
在我的 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 有一个名为 "paymentType" 的字段,它是一个枚举(称为 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;
}
}
假设在我的第 1 步页面中,我只想将这些值中的 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>
尝试:
<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>