2016-03-14 84 views
0

在我的Spring Webflow(具有JSP視圖)中,我有一個包含其某個字段的枚舉的模型。我需要一個帶有一組單選按鈕的表單,其中只包含一些可能的枚舉值,我似乎無法破解如何去做。將單選按鈕綁定到Spring Webflow中的特定枚舉值

所以我的流程是這樣的:

<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)可能看起來soemthing這樣的:

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> 

回答

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>