集成Spring MVC和JSF 2.1 [英] Integrating Spring MVC and JSF 2.1

查看:98
本文介绍了集成Spring MVC和JSF 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个庞大的只读RESTFUL应用程序,该应用程序是在Spring MVC和Hibernate-Search中构建的,该应用程序将一些数据编组为json和xml,供移动应用程序和监视应用程序使用.

I have a huge read-only RESTFUL application built in Spring MVC and Hibernate-Search that marshals some data to json and xml to be consumed for a mobile app and a monitoring application.

我们的网址非常简单,我们有以下网址:

Our urls are pretty simple, we have this:

server:port/entity/id/?marshalling = json

server:port/entity/id/?marshalling=json

server:port/entity/id/?marshalling = xml

server:port/entity/id/?marshalling=xml

有时

server:port/entity/id/?marshalling = something& filterProp = entity.prop& ordering = desc

server:port/entity/id/?marshalling=something&filterProp=entity.prop&ordering=desc

现在我需要使用JSF 2.1为此做一个表示层,并添加一些用户管理功能,而我在想这样的事情:

Now I have a requirement to make a presentation layer for this using JSF 2.1 and adding some user admin capabilities and I was thinking in something like this:

server:port/entity/id/?marshall = html

server:port/entity/id/?marshall=html

或完全省略marshall请求参数.

Or omitting entirely the marshall request parameter.

现在.据我所知,您只能将JSF 2.1和Spring Web Flow耦合,而不能直接将Spring MVC耦合.有人知道我该怎么满足这个要求吗?

Now. As far as I know, you can only couple JSF 2.1 and Spring Web Flow, not Spring MVC directly. Anyone know how can I accomplish this requirement?

推荐答案

Spring MVC和JSF都在单独的servlet上工作,这些servlet只能映射到与另一个servlet不冲突的上下文,因此这不容易实现,并且如果您成功了,那基本上就是一个巨大的黑客.

Both Spring MVC and JSF work on seperate servlets that can only be mapped to a context that doesn't conflict with another servlet, so this cannot be done easily and if you succeed then it is basically an enormous hack.

如果我绝对必须这样做((我不会) ),那么我可能会使用marshall servlet克隆我的JSF请求,然后使用WebClient将该请求发送到我的FacesServlet. ,然后将返回的WebClient响应复制到我的marshall servlet响应中并返回.这对用户是透明的,但高度混乱且可能不安全.

If I absolutely had to do it this way (which I wouldn't), then I would probably use the marshall servlet to clone my JSF requests, send that request to my FacesServlet using a WebClient, and then copying the returning WebClient response into my marshall servlet response and return that. This would be transparent to the user but highly messy and potentially insecure.

实现单独的基于Web的表示层的最佳方法是将对表示层的请求映射到FacesServlet,这样就不会直接调用RESTFUL Web服务.

The best way to implement a seperate web based presentation layer would be for requests to your presentation layer to be mapped to the FacesServlet so that your RESTFUL web services do not get called directly.

Actor->/admin/page.jsf-> FacesServlet-> JSF View-> JSF控制器->业务逻辑层-> RESTFUL Web服务

Actor - > /admin/page.jsf -> FacesServlet -> JSF View - > JSF Controller -> Business Logic Layer -> RESTFUL Web Services

通过这种方式,您的RESTFUL Web服务可以返回XML或JSON数据并充当DAO,您的业务逻辑层可以对此执行附加的逻辑.

In this way your RESTFUL web services can return XML or JSON data and act as your DAO, your Business Logic layer can perform additional logic on that.

这篇关于集成Spring MVC和JSF 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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