Java 如何在SpringWebFlow中验证集合?
我正在使用SpringWebFlow 我需要检查我是否有至少15个类型实践集合,如果没有,我就不能转换到下一个流 我的注册流程:Java 如何在SpringWebFlow中验证集合?,java,spring,validation,spring-webflow-2,Java,Spring,Validation,Spring Webflow 2,我正在使用SpringWebFlow 我需要检查我是否有至少15个类型实践集合,如果没有,我就不能转换到下一个流 我的注册流程: <view-state id="practices" view="RegisterPractices" model="labs"> <transition on="add" to="createNewPractice"></transition> <transition on="next" to
<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>
实践
实践
活动
行动
${practice.practice}
实现德雷瓦
视图状态实践只是一个添加了实践列表的jsp
我尝试过使用customValidator,但无法处理MessageBuilder.source(),因为该视图中没有任何对象
我也尝试过使用decision state,但我无法显示类似“您必须选择至少15个实践才能继续”这样的消息,所以此自定义验证器无法工作
@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());
}
}
}
@组件
公共类LabsValidator{
公共void validatePractices(最终实验室、最终验证上下文){
if(labs.getPractices().size()<15){
context.getMessageContext().addMessage(新MessageBuilder().error().code(“labs.practices.min15”).build());
}
}
}
为什么您不能在实验室模型上的自定义验证器中执行new MessageBuilder().error().source(“实践”)?因为我想如果我有一个处于该视图状态(jsp)的字段,我就无法指示源。工作得很好,我在捕获消息时遇到了问题。非常感谢。