Hello Everybody,
I'm using Spring MVC and Spring WebFlow to develop a web application. On flow start, some actions store data in the flow scope. For example,
Previous statement queries a database and initializes a collection of objects. This collection is dynamic and can change frequently. Users will be able to choose one element of this collection through a select HTML element. For example,Code:<on-start> <evaluate expression="manager.getCollection()" result="flowScope.collection" /> ... </on-start>
The whole flow includes several steps during which the collection doesn't change. So, there is not need to query the database once again, at least till the last step.Code:<form:select path="item"> <form:option value=""> </form:option> <c:forEach var="itemInCollection" items="${collection}"> <form:option value="${itemInCollection.id}">${itemInCollection.description}</form:option> </c:forEach> </form:select> <form:errors path="item" element="p" />
The chosen item is bound to a property of a POJO.
Code:<view-state id="enterDetails" model="command"> <binder> <binding property="item" /> ... </binder> ... <transition on="proceed" to="..." /> <transition on="cancel" to="cancel" bind="false" /> </view-state>As you can note, users choose an ID of an item and send it to the server. At server side, the property to which user's choice should be bound is an object. That is, I need string to object conversion. Reading documentation at Spring side, I read that the most appropriate way to do so is using a formatter.Code:public class Command extends java.io.Serializable { ... private Item item; ... }
However, as far as I know in the parse method I can only access the user input, that is the item's id. Of course, I could query the database again using such id to get the Item but the application will be used by a big number of users and I wouldn't like to query the database so much. My question is: there is a way to access the collection stored at the flow scope from the formatter? If I am able to access such collection, there is no need to query the database again at least till the last step of the flow.Code:@Override public Item parse(String text, Locale locale) throws ParseException { ... }
Thanks in advance.
Best wishes,
Sandy


Reply With Quote
