jsf - JSF 是否支持 MVVM 设计模式?

标签 jsf design-patterns jsf-2

我现在正在我的一个应用程序中使用 ZK 框架。 ZK Framework 支持 MVC 以及 MVVM 设计模式。现在对于一个新项目,我想使用 JSF。 JSF 是同时支持这两种设计模式还是只支持 MVC?

最佳答案

不,jsf 不支持 MVVM 设计模式,仅支持 MVC。它仅用于桌面应用程序。JSF 也称为 MVC fremework。

来自 http://blog.oio.de/2011/12/05/jsf-and-mvvm/ :

The first M in MVVM stands for Model, and it is the very same model that we use in our MVC approach. In fact MVVM does not replace MVC, I rather prefer to see it as an additon to MVC, so there is nothing new here.

The first V in MVVM stands for View and again, there is nothing new to this part. It is the component that takes care of the client side representation. So there wont be any notable change to our views since we will continue to define them using Facelets.

VM in MVVM stands for the ViewModel, our client side model. The ViewModel is bound to the Model but it is exisitent only on the client side, though you are free to sync it whenever needed with the Model on the server side. But, more important is, that you can do whatever you want on the client side without having to send callbacks to the server.

First of all we need a next-generation-JSF-implementation, which supports the MVVM concept. The ViewModel would be created by this yet to come JSF implementation before a requested view is delivered to the client. Our ViewModel will be created from one or more JSF Managed Beans that form the Model. I can think of a nice set of class- and field-level annotations to tell JSF what parts of our model should make up the ViewModel on the client side. Once the view is delivered to the client, the ViewModel will be manipulated by client side scripts upon the form is submitted. Then, in the following iteration of the request processing lifecycle, JSF has to deal with resynchronization between ViewModel and Model. Admittedly, this might be the most tricky part, but I’m confident that the Next-Gen JSF Impl will manage to do that ;-)

来自 Understanding JSF as a MVC framework :

The nodes M, V and C are a maximum connected graph, meaning each part can communicate with every other part. E.g. if the model changes, it can push this change to the view. This is particularly visible in case there are multiple representations of the view in a desktop application. Change one, and see the other update in real-time.

Due to the client/server and request/response nature of web applications, classic MVC doesn't map 1:1 to most web frameworks.

更多信息请参见此链接:http://www.tutorialspoint.com/jsf/jsf_architecture.htm

关于jsf - JSF 是否支持 MVVM 设计模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19925405/

相关文章:

jsf - session bean 在 HTTPS-DNS 组合上丢失

oop - 原型(prototype)设计模式的克隆功能?

CSS 在 JSF 2.0 元素中不起作用

jsf - 是否跨 session 范围的 JSF 支持 bean 观察到 CDI 事件

java - 如果验证失败,如何在验证阶段之后 checkin ?

jsf - pageflowScope 在 ADF Faces 中到底有什么作用?

c++ - 根据用户输入创建相应的派生类的最佳实践是什么?

validation - 基于下拉列表选择的输入文本验证

java - Seam 和 JSF - 误解 <h :inputHidden/>?

design-patterns - JPA继承和EJB多态性