使用JSF作为Spring MVC的视图技术 [英] Using JSF as view technology of Spring MVC

查看:85
本文介绍了使用JSF作为Spring MVC的视图技术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在实现一个小型的Spring MVC PoC,并且我希望使用JSF作为视图技术,因为公司中的大多数人都习惯于带有Primefaces环境的J2EE.

I am currently implementing a small Spring MVC PoC, and I would like to use JSF as the view technology since most people in my company are used to a J2EE with Primefaces environment.

Spring MVC 3是否支持JSF或仅支持JSP?我读过多篇文章,将两者混为一谈.

Does Spring MVC 3 support JSF, or simply JSP? I have read multiple articles mixing the two.

我需要创建一个吸引人的UI.使用Spring MVC和JSP作为视图技术,是否有一种简单的方法?

My need is to create an appealing UI. Is there a simple way to do this using Spring MVC with the JSP as the view technology?

我们的应用程序在多个页面中使用时间表/日历.这基本上是一个时间管理应用程序

Our application uses schedules/calendars in multiples pages. It's basically a time management APP

推荐答案

您在犯一个概念性错误. JSF不是视图技术. JSF是一个MVC框架.就像Spring MVC一样,尽管两者都有不同的意识形态. JSF是基于组件的MVC,而Spring MVC是基于请求的MVC.因此,他们是完全的竞争对手.您不能混合它们.您应该选择一个.相反,JSP和Facelets是真正的视图技术.从Java EE 6(2009年12月)开始,已弃用,并且被Facelets(XHTML)取代,作为JSF的默认视图技术.

You're making a conceptual mistake. JSF is not a view technology. JSF is a MVC framework. Exactly like as Spring MVC, albeit they have both a different ideology; JSF is component based MVC and Spring MVC is request based MVC. Thus they are full competitors. You cannot mix them. You should choose the one or the other. Instead, JSP and Facelets are true view technologies. Since Java EE 6 (December 2009), JSP is deprecated and replaced by Facelets (XHTML) as default view technology for JSF.

您可以将Spring MVC与 JSP视图技术.您还可以将Spring MVC与 Facelets视图技术(以及 jQuery UI .这也正是PrimeFaces在幕后使用的东西. PrimeFaces是一个基于jQuery的JSF组件库.

You can use Spring MVC with JSP view technology. You can also use Spring MVC with Facelets view technology (and many others). But you can not use Spring MVC with JSF components let alone with JSF component libraries like PrimeFaces. JSF output components may work, but JSF input components won't work at all. Spring MVC has already its own <form:xxx> tags for input. Even if you mix them, you will end up with half of the functionality from both frameworks in a mingled and confusing code base. This is not making any sense. If all you want is to use the same UI as PrimeFaces, just grab jQuery UI. It's also exactly what PrimeFaces is using under the covers. PrimeFaces is a jQuery-based JSF component library.

从另一方面来说,将Spring IoC/DI与Spring MVC混淆也可能很好. Spring IoC/DI依次可用与JSF一起使用.您可以用Spring托管Bean设施(@Component和好友)替换JSF托管Bean设施(@ManagedBean和好友),通常仅出于在JSF支持Bean中使用@Autowired的目的.就是这样. JSF MVC框架的生命周期,JSF组件和视图技术保持不变.与之等效的标准Java EE将使用 CDI (和

From the other side on, it can also be very good that you confused Spring IoC/DI with Spring MVC. Spring IoC/DI is in turn usable together with JSF. You can replace the JSF managed bean facility (@ManagedBean and friends) by Spring managed bean facility (@Component and friends), usually with the sole purpose in order to use @Autowired in a JSF backing bean. But that's it. The JSF MVC framework lifecycle, the JSF components and the view technology remain unchanged. The standard Java EE equivalent of that would be using CDI (and EJB).

同样的故事适用于Spring Security.您可以将其与JSF一起使用,但是,为了配置它,您不应该遵循Spring Security + Spring MVC目标的文档/示例进行配置,而只能遵循Spring Security + JSF的文档/示例.请注意,仅当您用Spring托管Bean设施替换JSF托管Bean设施时,对业务操作的Spring Security约束才起作用.因此,仍然需要如上一段所述的在JSF中集成Spring".通过web.xml中的<security-constraint>条目,可以使用容器托管的安全性(JAAS/JASPIC)来实现所有这些的等效标准Java EE.

The same story applies to Spring Security. You can use it together with JSF, you should however not follow Spring Security + Spring MVC targeted documentation/examples in order to configure it, but only Spring Security + JSF ones. Do note that Spring Security constraints on business actions only works when you replace the JSF managed bean facility by Spring managed bean facility. So that would still require a "Integrate Spring in JSF" as described in previous paragraph. The standard Java EE equivalent of this all would be using container managed security (JAAS/JASPIC) via <security-constraint> entries in web.xml.

同样的故事也适用于Spring WebFlow.您还需要确保您使用的是Spring WebFlow的最新版本,因为旧版本会导致 Faces Flows 功能.是标准Java EE API的一部分,因此基本上使Spring WebFlow变得多余.

The same story also applies to Spring WebFlow. You only also need to make sure that you're using most recent version of Spring WebFlow as older versions cause conflicts when used together with multiple JSF component libraries. Moreover, since JSF 2.2, new Faces Flows feature was introduced as part of standard Java EE API, hereby basically making Spring WebFlow superfluous.

然后是Spring Boot.在Java EE中没有直接等效项. Spring Boot基本上使您能够使用普通的Java应用程序类和main()方法以简单而抽象的方式"执行Java EE应用程序.如果没有Spring Boot,这肯定是有可能的(否则Spring Boot将永远不存在),因为您必须根据其文档考虑服务器特定的细节,因此配置方面的工作仅需一点点.例如: Undertow

Then there is Spring Boot. This does not have a direct equivalent in Java EE. Spring Boot basically enables you to execute a Java EE application using a plain Java application class with a main() method "in an easy and abstract way". Without Spring Boot it's surely possible (otherwise Spring Boot would never have existed), it's only a bit more work as to configuration as you have to take into account server-specific details based on its documentation. For example: Undertow and Jetty.

如果真的有必要,请回到JSF和Spring MVC,可以在同一Web应用程序中安全地彼此相邻运行Spring MVC和JSF,但是它们不会在服务器端进行互操作.它们将完全独立运行.如果JSF生成的HTML页面中的某些JavaScript恰巧在同一Web应用程序中调用基于Spring的REST Web服务调用,则它们最多将在客户端彼此接触.但是,该Spring Web服务于是不需要/不必了解有关JSF的任何信息即可做出相应的响应.与该Spring REST Web服务等效的标准Java EE是 JAX-RS .

Coming back to JSF and Spring MVC, if really necessary, you can safely run Spring MVC and JSF next to each other in same web application, but they won't interoperate in server side. They will run completely independently. They will at most touch each other in the client side, if some JavaScript in a JSF-generated HTML page happens to invoke a Spring based REST web service call in the same web application. But that Spring web service would then not need/have to know anything about JSF in order to respond accordingly. The standard Java EE equivalent of that Spring REST webservice is JAX-RS.

即将到来的Java EE 8将带有一个基于请求的新MVC框架,其名称仅为" MVC ",基于JSF和Spring MVC的经验教训,从而取代了Spring MVC,并提供了JSF的标准替代方案.

The upcoming Java EE 8 will come with a new request based MVC framework, named just "MVC", based on lessons of both JSF and Spring MVC, hereby supplanting Spring MVC and providing a standard alternative to JSF.

  • What exactly is Java EE?
  • Difference between Request MVC and Component MVC
  • What are the main disadvantages of Java Server Faces 2.0?
  • What is the need of JSF, when UI can be achieved from CSS, HTML, JavaScript, jQuery?
  • When is it necessary or convenient to use Spring or EJB3 or all of them together?
  • Spring JSF integration: how to inject a Spring component/service in JSF managed bean?
  • Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?

这篇关于使用JSF作为Spring MVC的视图技术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆