3 Replies Latest reply on Dec 24, 2009 2:31 PM by walterjwhite

    My own CustomSeamViewHandler

    poiu77

      Helo.


      I need write my own CustomSeamViewHandler extends SeamViewHandler.


      In my handler I want use EntityManager.


      How can I inject it to my handler (Can I?) or maybe is other way to get something from database.


      Thanks.

        • 1. Re: My own CustomSeamViewHandler
          walterjwhite

          Hi Darek,


          It should be possible.  I am guessing (without looking at the source) that you would call Components.getInstance(entityManager).  Of course, you would need to do that inside a Seam context.


          It is hard to say what might be the best option for you.  You could pass page parameters and then fetch content from the database using that parameter.  Depending on what you're doing, you may or may not need a custom view handler.




          Walter

          • 2. Re: My own CustomSeamViewHandler
            poiu77

            Hi Walter


            Thanks for advice. It works.


            I have Documents in my application witin alias field, template field and content field. When I put in browser http://context/{example}.seam I need show template from {template for example alias eq. /front.xhtml}. Whatever I write as {example}, application have to show site from template for document with alias equal {example}. In my CustomViewHandler I connect to database, find document by alias (example), then get template (eq. /front.xhtml) and put it in ViewRoot as viewId. It works.
            From this moment I don't know how show content in browser. I want show content from current document, so I need outject this object. I know how do this from Stateless EJB, but then I must connect to database second time. Is there a way do this from ViewHandler?


            Darek.

            • 3. Re: My own CustomSeamViewHandler
              walterjwhite

              Hi Derek,


              That sounds useful and like you're making good progress.  Can you post your view handler if you don't mind.


              Yeah, to set a variable in a context you can do this:


              Contexts.getEventContext().set(someVariable, someValue);


              You can choose whatever context you need there.  You just have to be careful that the one you choose is active.


              Let me know if that helps.



              Walter