0

我正在使用 Spring WebFlow

我需要检查我是否有至少 15 个类型的 Practices 集合,如果没有,我无法转换到下一个流程。

我的注册流程:

<view-state id="practices" view="RegisterPractices" model="labs">
        <transition on="add" to="createNewPractice"></transition>
        <transition on="next" to="items" validate="true"></transition>
        <transition on="back" validate="false" to="owners"></transition>
</view-state>
<subflow-state id="createNewPractice" subflow="addPractice">
        <output name="practica" />      
        <transition on="practiceAdded" to="practices">
            <evaluate expression="labs.addPractice(currentEvent.attributes.practice)"></evaluate>
        </transition>       
        <transition on="practiceCancel" to="practices"></transition>
</subflow-state>

jsp实践:

<h2>Practices</h2>  
    <table class="standard-table" cellpadding="0" cellspacing="0">
        <thead>
            <tr>
                <th>Practice</th>
                <th>Operation</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${ labs.practices }" var="practice">
            <tr>
                <td>${ practice.practice}</td>
                <td><c:choose><c:when test="${ practice.realize == 1}">Realize</c:when><c:otherwise>Deriva</c:otherwise></c:choose></td>
            </tr>
            </c:forEach>
        </tbody>
    </table>
    <div>
        <a href="${flowExecutionUrl}&_eventId=add">Add a New Practice</a>
            <a href="${flowExecutionUrl}&_eventId=next">Back</a>
        <a href="${flowExecutionUrl}&_eventId=back">Next</a>
    </div>

View-State 实践只是一个添加了实践列表的 jsp。

我尝试过使用 customValidator 但我无法处理 MessageBuilder.source() 因为我在该视图中没有任何对象。

我也尝试过决策状态,但我无法显示“您必须选择至少 15 种做法才能继续”这样的消息

4

1 回答 1

0

所以这个自定义验证器不起作用?

@Component
public class LabsValidator {

    public void validatePractices(final Labs labs,final ValidationContext context) {
        if(labs.getPractices().size() < 15) {
            context.getMessageContext().addMessage(new MessageBuilder().error().code("labs.practices.min15").build());
        }
    }

}
于 2012-09-11T13:20:28.063 回答