问题
Spring MVC has become a very popular framework for building enterprise web applications. Any complex web application has certain flows that need to be coded, including some conditional flows (i.e., show order processed if the credit card information was correct, or validation errors if something was not entered correctly).
When does it make sense to use Spring WebFlow on top of Spring MVC? What should be the decision making process regarding using Spring WebFlow?
回答1:
If you have a web application that has some application process. For example, if you have some kind of sign up process that one button can go to one page while another can go to a different page. Spring Webflow can handle transitioning to different sets of processes very well.
Basically, if some part of your application is linked and pages depend on each other during the course of an execution SWF is good to use.
回答2:
What I personally like in webflow most are 2 things:
- Ability to inherit flows and view-states. This is quite handy when you have some common logic aspects that you want to share between different parts of your application. For example, you have CRUD logic that you want to abstract in separate flow and then allow child flows to inherit this logic. Each flow can have input and output, so your logic can be very fine-grained.
- Powerful testing framework. It is possible to cover almost all aspects of your flow logic in unit tests. You can emulate many things programmatic, such as action firings, transitions from one view to another, flow persistence handling and and so on
What I don't like is inconsistency and poor backward compatibility of newer versions. For example, latest webflow 2.1 is not compatible with JSF 1.x jira. There are also numerous problems with integrating with Spring Security. For example, in spring security 3.x they just changed some package names In general, as Sasi mentioned, webflow will almost force you separate your logic in different webflows - and this is nice I think.
回答3:
One problem that webflow solves efficiently is it cleanly separates (or at least it makes very hard to mix) business logic from your control logic.
Agree with @John on the use cases but I would like to point out that once you start using webflow heavily, you will find yourself writing a lot of xml files (since in webflow you specify all the flows in xml files). This is almost a deal breaker for me personally.
回答4:
I have used MVC and SWF. Personally I prefer SWF over MVC due to the following two solid reasons:
- Spring MVC has no built in mechanism for session control across multiple tabs in same browser.
- Handling browser go backs is easier in SWF than MVC.
来源:https://stackoverflow.com/questions/3345013/when-does-it-make-sense-to-use-spring-webflow-on-top-of-spring-mvc