1 Reply Latest reply on Aug 13, 2008 7:29 PM by damianharvey.damianharvey.gmail.com

    How to store variables within seam sessions. How to use regular servlets with seam.

    jj2themax

      Hi There.


      I'm relatively new to JBoss seam. I find that it has a lot of potential. However, I have some problems and can't seem to find documentation anywhwere.


      I'm trying to develop a facebook app on top of JBoss seam. However, I would want a way to save the facebook session somewhere so that I could reuse it at other pages. So here's my problems listed down :


      1. How to store the sessionKey(Obtained from facebook) so that I could reuse it in other pages/servlets/jsfs. Can I use the contexts provided by seam (Stateless,statefull, application, conversation, etc)?


      2. I have managed to integrate regular servlets into seam using ContextualHttpServletRequest. However, how can i use the bijections within servlets?
      For example, in jsf, i can use  ${user.username}. Then, in the bean, i use the @In / @Out annotations. How can I achieve the same thing in servlets?


      I hope any experts could help me with this. It'll be much appreciated.


      Thanks

        • 1. Re: How to store variables within seam sessions. How to use regular servlets with seam.
          damianharvey.damianharvey.gmail.com

          I haven't looked at anything to do with FaceBook Apps but:


          1) You can use any of these contexts depending on how long you want the sessionKey to stick around for. Given it's name, I'd think the session context sounds most likely. Either outject it into the Session context eg;


          @Out(scope=ScopeType.SESSION)
          private String sessionKey;
          


          or set it yourself inline in a method:


          Contexts.getSessionContext().set("sessionKey", sessionKey);
          



          2) You could do the whole thing with servlets, but it sounds painful. In a servlet you can access Seam components like this:


          Component.getInstance("mySeamBean");
          


          but you may find it more useful just to have Seam Beans (SLSB, SFSB, POJO, whatever) and get the ServletResponse eg:


          public void someAction() {
             try {
                final HttpServletResponse resp = (HttpServletResponse) facesContext.getExternalContext().getResponse();
                
                resp.getOutputStream().write(...whatever you want...);
                resp.getOutputStream().flush();
                resp.getOutputStream().close();
                facesContext.responseComplete();
          
             } catch (IOException e) {
                e.printStacktrace();
             }
          }
          


          Cheers,


          Damian.