-
1. Re: get a session seam variable from servlet
mikkus70 Mar 24, 2010 2:24 PM (in response to aj1m)A servlet is instantiated by the container, not by Seam, and therefore, even if you annotate it as such, it is not a Seam component. Not being a component, it is not managed by Seam and cannot therefore benefit from Seam services such as bijection.
In order to access a component from non-component code, you can use Seam API calls:
((Mybean)Component.getInstance("myBean")).setVar("value");
Also, note that servlet requests are not contextual (so, you don't have Seam contexts associated with it, i.e., you don't have a conversation context). This is because the request is not processed by Seam, but by your own servlet, and therefore Seam does not have the information necessary to determine what contexts apply to your request.
What this means is that, even if you access a component via the API, if it tries to inject other components into itself, those other components could be unavailable. To have access to the contexts of the
normal
Seam application, you can give Seam the chance tosee
the request and determine its context, doing the following in your servlet:protected void doGet(HttpServletRequest request, HttpServletResponse response) { new ContextualHttpServletReques(request) { @Override public void process() { doRequest(request, response); } }.run(); } private void doRequest(final HttpServletRequest request, final HttpServletResponse response) { response.setContentType(...); // from here you can get hold of a component, having Seam contexts visible. ((MyBean)Component.getInstance("myBean")).setVar("value"); }
What this does is let Seam get hold of the request and process it as if it arrived to its own servlet. I haven't tried this on an external servlet, but it does work fine from the Resource Servlet.
-
2. Re: get a session seam variable from servlet
aj1m Mar 24, 2010 2:26 PM (in response to aj1m)Here is the solution :
HttpSession session = request.getSession(true); Mybean mybean = new Mybean(); mybean = (Mybean)session.getAttribute("mybean"); mybean.getvar();
;)
-
3. Re: get a session seam variable from servlet
aj1m Mar 24, 2010 3:44 PM (in response to aj1m)and to set a value :
HttpSession session = request.getSession(true); Mybean mybean = new Mybean(); mybean = (Mybean)session.getAttribute("mybean"); mybean.setvar(); session.setAttribute("mybean", mybean);