2

I've just come across a rather odd problem whilst testing my applications webflows.

I have two seperate webflows that are accessed once a user logs in depending on whether the user is male or female, they begin a process which sends them on a webflow. One for males, a different one for females.

So to test my app, I login as a male user and enter the flow, thats all fine.. then either by logging out and logging in as a female (or logging in as a female user in a different browser) I then attempt to go through the female process but Bang I get an exception:

Error 500: java.util.Collections$UnmodifiableMap cannot be cast to groovy.lang.Closure
Servlet: grails
URI: /ACUREG/grails/applicant/ma.dispatch
Exception Message: java.util.Collections$UnmodifiableMap cannot be cast to groovy.lang.Closure
Caused by: java.util.Collections$UnmodifiableMap cannot be cast to groovy.lang.Closure
Class: ApplicantController

Now this is strange, as the reverse is also true, If I started first going through as a female, then attempt to try the Male process, the same issue occurs but this time the exception will point to the first event in the male webflow code...

Does anyone know why this may be happening? I did think its perhaps something to do with two webflows in the same controller but after seperating them into their own controllers and still seeing the same issue thats clearly not the case.

Thanks,

skaffman
  • 398,947
  • 96
  • 818
  • 769
David Brown
  • 3,021
  • 3
  • 26
  • 46
  • Source would help. Can it be that you use [] instead of {}? – Victor Sergienko Dec 21 '10 at 14:22
  • The thing is both flows work as expected when I restart the program between tries. E.g Restart, Try flow A.. all OK, restart, try flow B, all OK.. but if I try flow A, log out and try flow B, then crash, – David Brown Dec 21 '10 at 17:33
  • Adding some debugging for webflow and we can see the point it crashes: registry.FlowDefinitionRegistryImpl Getting FlowDefinition with id 'applicant/fa' builder.DefaultFlowHolder Assembling the flow for the first time errors.GrailsExceptionResolver java.util.Collections$UnmodifiableMap cannot be cast to groovy.lang.Closure – David Brown Dec 21 '10 at 17:35
  • Made a little progress, The problem appears to be related to the initialization{} block. Each flow has an initialization block in which I read data and populate command objects which are used throughout the flow. If I comment out the initialization block entirely I can then call and show each of my two flows. If it's there I can only call one flow. – David Brown Dec 21 '10 at 18:19

2 Answers2

1

Just to provide an answer here as much as I can, I narrowed the problem down to a method I call in the initialisation block where I call a service method that updates the properties of a command object with the values from matching property names from a domain object.

As long as the class names of the command objects are different, then there is no problem but in my case the first page of each of my webflows use the same command object class and for some reason unknown this was causing the exception. By duplicating this particular command object and renaming one of them so that it was specific to one of the webflows, the problem disappears.

I wish I could have seen a more useful exception and indication of where the problem occurred and I may have saved a day tracking it down.

So in short, if you are using multiple webflows with command objects, be careful as they seem to be 'cached' by name somehow...

David Brown
  • 3,021
  • 3
  • 26
  • 46
  • 1
    This may be too late for you, but I hope this helps someone else... Basically, if you are thinking of using webflow in grails, please don't. It is very invasive (affects the way you write your GSPs, affects the way DB transactions are handled, etc), but offers very little use. It usually isn't that hard to roll your own... The Groovy DSL that the grails plugin provides is nice, but it has caused no end of problems for our team and anyone else who I've spoken to about it... – Adam C Dec 22 '10 at 16:19
0

The problem was down to webflow events having the same name across multiple webflows. When I renamed the events so they were all different, no more problems.

David Brown
  • 3,021
  • 3
  • 26
  • 46