Java EE JSF vs Spring MVC

近期一直在讀有關 Java EE 7 的資料,發現它真的很複雜,由 Persistence Layer、Business Layer 到 Web Layer 都有框架照顧到。Spring 亦是如此。

JSF 似乎成為了 Java EE 7 框架內 MVC 的標準。看起來似乎很不慣,跟自己用過的網頁框架很不同。但原來這是因為它是 Pull-based web framework(也叫做 Component-based web framework),靠 View 去找對應的 Controller 工作。這就如 ASP.net 的 Webforms 和 MVC 的分別。

根據維基百科,Push-based 和 Pull-based 有如此不同:
Most MVC frameworks follow a push-based architecture also called "action-based". These frameworks use actions that do the required processing, and then "push" the data to the view layer to render the results. Django, Ruby on Rails, Symfony, Spring MVC, Stripes, CodeIgniter are good examples of this architecture.

An alternative to this is pull-based architecture, sometimes also called "component-based". These frameworks start with the view layer, which can then "pull" results from multiple controllers as needed. In this architecture, multiple controllers can be involved with a single view. Lift, Tapestry, JBoss Seam, JavaServer Faces, (µ)Micro, and Wicket are examples of pull-based architectures.

Play, Struts, RIFE and ZK have support for both push and pull based application controller calls.


這跟 Spring MVC 很不同,我之後找到了這幅圖,比較了兩種模式(圖片來源):
web_frameworks

之後我又找到一些整個 Java EE 框架跟 Spring,和 JSF 跟 Spring MVC 的比較,它們有好多相似的地方,但就在 Web Layer 顯得很不同:
SlideShare - Java EE and Spring Side-by-Side
SlideShare - jDays2015 - JavaEE vs. Spring Smackdown
Spring 4, Java EE 7 or Both?
A Developers Perspective on Spring vs JavaEE
SlideShare - Comparing JVM Web Frameworks - February 2014
SlideShare - JSF 2.2

原來在未來的 Java EE 8 框架內,又會在於 JSF 這種 Pull-based web framework 外,加入另一種 Push-based 的 MVC 規範,不知道又會帶來什麼影響。
A new MVC framework for Java EE 8
Why Another MVC Framework in Java EE 8?
MVC 1.0 by Example
JSR 371: The last web framework you’ll ever look at

本文連結