从Web服务访问FacesContext [英] Accessing FacesContext from Web Service

查看:101
本文介绍了从Web服务访问FacesContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web服务,该服务将由我编写的客户端调用.在Web服务中,我需要使用应用程序范围的对象,这可以减轻系统上应用程序的负担.我已经实现了我的应用程序范围内的对象,如此问题.

I'm developing a Web Service which will be called by clients which are written by me. In the web service I need to use application-wide objects which eases the load of application on the system. I have implemented my application-wide objects as shown in this question.

我可以在jsf页面中毫无问题地使用我的对象,如下所示.

I can use my object in a jsf page with no problem as follows.

MyObject mo = (MyObject) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("MyObjectsName");

但是在Web服务请求中使用它时,FacesContext.getCurrentInstance()返回null.有什么方法可以在Web服务中使用FacesContext.

But when it comes to use it in a Web Service Request FacesContext.getCurrentInstance() returns null. Is there any way to use the FacesContext in a web service.

推荐答案

它为null,因为Web服务不是通过Faces Servlet来的.这就是应有的方式,因为Web服务与JSF无关.

It is null, because web services don't come through the Faces Servlet. And this is the way it should be, because web services have nothing to do with JSF.

如果您使用的是jax-ws实现,则可以使用:

In case you are using a jax-ws implementation, you can use:

@Resource
WebServiceContext context;

这将注入WebServiceContext,通过它您可以:

This will inject the WebServiceContext, by which you can:

ServletContext servletContext = (ServletContext) 
     context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);

有了ServletContext,您就可以访问应用程序作用域的对象.

And having the ServletContext, you can access your application-scope objects.

这篇关于从Web服务访问FacesContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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