Question

I am using Spring WebFlow

I need to check if i have at least 15 collections of type Practices, if not I can't transite to the next flow.

my register-flow:

<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>

The jsp practices:

<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>

the View-State practices is just a jsp with a list of practices Added.

I have tried with a customValidator but I cant handle the MessageBuilder.source() because I don't have any object in that view.

I have tried too with decision-state but with that I can't show a message like "You have to select at least 15 practices to continue"

Was it helpful?

Solution

so this custom validator won't work?

@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());
        }
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top