简体   繁体   English

CDI / JSF和JAX-RS?

[英]CDI/JSF and JAX-RS?

I would like to use RESTful services in a CDI/JSF2 application. 我想在CDI / JSF2应用程序中使用RESTful服务。 I am not very familiar with JAX-RS however I have read that its lifecycle does not play well with CDI/JSF2. 我对JAX-RS不是很熟悉,但是我已经读过它的生命周期与CDI / JSF2不兼容。 Is it possible to incorporate JAX-RS with CDI/JSF2 in a JEE6 stack? 是否可以将JAX-RS与CDI / JSF2合并到JEE6堆栈中? If not are there alternatives? 如果没有替代品?

thanks 谢谢

You can use JAX-RS just fine along side a JSF application, however, they don't play well together . 你可以在JSF应用程序旁边使用JAX-RS,但是它们并不能很好地协同工作 For instance, you can't use JAX-RS to have " http://localhost:8080/story/92/ " return a JSF page with a Story entity with ID 92. 例如,你不能使用JAX-RS让“ http:// localhost:8080 / story / 92 / ”返回一个带有ID为92的Story实体的JSF页面。

You can, however, use PrettyFaces to do something very similar to this. 但是,您可以使用PrettyFaces执行与此非常相似的操作。

JAX-RS makes sense for non-JSF resources. JAX-RS对非JSF资源有意义。 " http://localhost:8080/story.xml " makes perfect sense for JAX-RS. http:// localhost:8080 / story.xml ”对于JAX-RS非常有意义。

You can call your rest services from your JSF templates. 您可以从JSF模板调用您的休息服务。 For example you can run your rest services from http://localhost:8080/services/ while your JSF page is returned on http://localhost:8080/index.xhtml . 例如,您可以从http://localhost:8080/services/运行您的休息服务,同时在http://localhost:8080/index.xhtml上返回您的JSF页面。 You can then write some custom javascript to call your rest services from your JSF page. 然后,您可以编写一些自定义JavaScript来从您的JSF页面调用您的其他服务。 This is actually the general practice with REST services so they can be consumed by many different UIs. 这实际上是REST服务的一般做法,因此它们可以被许多不同的UI使用。 JSF may not be the best for consuming REST services, but it is possible. JSF可能不是最好的消费REST服务,但它是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM