【问题标题】:Binding radio buttons to specific enum values in Spring Webflow将单选按钮绑定到 Spring Webflow 中的特定枚举值
【发布时间】:2016-03-15 08:16:56
【问题描述】:

在我的 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>

【问题讨论】:

    标签: java spring forms jsp spring-webflow


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 1970-01-01
      • 2012-05-18
      • 2014-10-14
      • 2013-08-19
      • 1970-01-01
      • 1970-01-01
      • 2018-06-09
      • 2012-08-19
      相关资源
      最近更新 更多