Nov 29th, 2005, 04:25 PM
Calling A Form Controller With Conditions
I need to have a form controller whether or not can be called by one particular user based on some business logic. Take an on-line book store as an example: the author of a book can't submit a comment/review of his/her own book; a person only can submit one comment/review per book. I don't want to have a custom tag to block the user access of the comment/review submission button/URL when that condition isn't met, nor solo rely on a DB schema constraint to enfore the business logic. I am sure the WebFlow can deal this situation easily. How can I solve this problem without using WebFlow, if I can?
Thanks advance for your inputs.
Nov 30th, 2005, 03:35 AM
It depends on how you want to enforce these rules.
If you simply want to wrap the controller with guards, this is simple, but what happens if the guard fails, i.e. an author does visit the "comment" url for this own book?
Basically you need to think about how to prevent them getting there in the first place (probably with some logic to show/hide the "comment" URL) and a guard on the controller itself.
For the first bit I would probably write a custom tag which encapsulates the logic, for the second, I would either implement a decorator, or do something clever with AOP, wrapping the controller. You could even put the guard directly into your controller.
If you want code samples, give a bit more info, and you existing controllers
Nov 30th, 2005, 11:13 AM
I later though using another interceptor could be a solution. There already is a sign on interceptor in place for the form controller. So, a chain of interceptors would be applied on the URL. Since I haven't test the implementation yet, I assume the interectpors would be walked over with the order listed on the configuration file, servlet.xml. If not, I need to figure out another solution.
Thanks for your inputs, yatesco.