|
|
Spring Roo Web Flow Edit/Create
Spring Roo: 1.1.0.M3
Spring Web Flow: 2.1.1.RELEASE
I was wondering if someone could help me with my web flow configuration.
I ran the web flow command, it it created webflow-config.xml
First Question: Is roo setting up the web flow configuration correctly?
I had to Change the Repositories to the Spring Enterprise Bundle in order to get it to download everything it needed (granted I am using M3 Roo so maybe this is the reason)
Second Question: I had to add the jpaListFlowExecutionListener to the configuration to get it to work. Is this correct, or did a mix and match things? Just using the Roo web flow command I couldn't get a domain object to persist during the flow.
I mention the first two question, because if I have my web flow configured incorrectly it might explain the following:
I created a flow to create one of my domain objects created with Roo.
Basic object that has a couple of Set collections to references
Course (name, description)
DeliveryType (name, code)
Instructor (firstName, lastName)
So a Course has 1 Delivery Type
Code:
field reference --fieldName deliveryType --type ~.domain.DeliveryType --class ~.domain.Course
and can have 0 or more Instructors
Code:
field set --class ~.domain.Course --fieldName instructors --element ~.domain.Instructor --mapped by course cardinality ONE_TO_MANY
So I created a courseflow, that would collect the course information (step1), then allow the user to pick one or more instructors(step2)
This works fine with the following flow:
Code: lt;on-startgt;lt;evaluate expression=quot;new com..petclinic.domain.Course()quot; result=quot;flowScope.coursequot; /gt; lt;/on-startgt; lt;view-state id=quot;courseDetailsquot; model=quot;coursequot;gt; lt;on-rendergt;lt;evaluate expression=quot;T(com..petclinic.domain.DeliveryType).findAllDeliveryTypes()quot; result=quot;requestScope.deliveryTypesquot;/gt; lt;/on-rendergt; lt;transition on=quot;proceedquot; to=quot;instructorAssignmentquot;/gt; lt;on-exitgt;lt;evaluate expression=quot;course.persist()quot; /gt; lt;/on-exitgt; lt;/view-stategt;
lt;view-state id=quot;instructorAssignmentquot; model=quot;coursequot;gt; lt;on-rendergt;lt;evaluate expression=quot;T(com..petclinic.domain.Instructor).findAllInstructors()quot; result=quot;requestScope.instructorsquot;/gt; lt;/on-rendergt; lt;transition on=quot;proceedquot; to=quot;end-statequot;/gt; lt;on-exitgt;lt;evaluate expression=quot;course.merge()quot; /gt; lt;/on-exitgt; lt;/view-stategt;
lt;end-state id=quot;end-statequot; view=quot;externalRedirect:contextRelative:/quot; /gt; lt;global-transitionsgt; lt;transition on=quot;cancelquot; to=quot;cancelledquot;/gt; lt;transition on=quot;savequot; to=quot;saveCoursequot;/gt; lt;/global-transitionsgt;
I wasn't able to use lt;persistence-context /gt; it kept giving me an error that the entityManager was bound to another from. Found some information, that said comment out the OpenEntityManagerInViewFilter in the web.xml.
This seemed to work, I could now use the lt;persistence-context /gt; but then I started getting detached entity errors, on any update done after the initial persist.
So I reverted it back, and I could now create the course. So I took the next step and tried to modify the flow to support Create or Edit.Code:
lt;input name=quot;idquot;/gt;
lt;decision-state id=quot;createOrEditquot;gt;
lt;if test=quot;id == nullquot; then=quot;createCoursequot; else=quot;editCoursequot; /gt;
lt;/decision-stategt;
lt;action-state id=quot;createCoursequot;gt;
lt;evaluate expression=quot;new com..petclinc.domain.Course()quot; result=quot;flowScope.coursequot; /gt;
lt;transition to=quot;courseDetailsquot; /gt;
lt;/action-stategt;
lt;action-state id=quot;editCoursequot;gt;
lt;evaluate expression=quot;T(com..petclinic.domain.Course).findCourse(id)quot; result=quot;flowScope.coursequot; /gt;
lt;transition to=quot;courseDetailsquot; /gt;
lt;/action-stategt;
Tested it out and Create still Works, but when I try editing, the courseDetails works fine, proceed to instructorAssignment and it blows up with LazyInitializationException: failed to lazily initialize a collection of role: com..petclinic.Course.instructors.
So it seems that Loading the course (Course.findCourse(id)) does something to the environment that prevents the children from loading.
So I guess the Roo part of the question is, Does Roo setup Web Flow 2.1.1 correctly for use with it's Roo created Entities?
Or would a better solution be to ditch Roo, and Follow the Web Flow 2.1.1 Reference Guide and Set things up that way?
And why are they different? I know there are probably lots of ways to setup Web Flow, but since Roo is supposed to do some of the basic setup for you, shouldn't the basic setup up match the Web Flow basic setup? I assume the Booking sample in Web Flow is using a basic setup. It would be nice if one could look at the booking sample, and see similar setup in Roo after issuing the web flow command.
Believe me, I'm not bitching, I think both tools are awesome, and I am sure my attempt to merge the two tools, messed something up.
So hopefully, someone can help me out with a clean config, and maybe some pointers. Or if anyone has some links to good sites, or books. I have already been through the Spring In Action 2nd Edition Web Flow Section. And searched through lots of tutorials.
Thanks in advance, |
|