• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling a Managed Bean method from Servlet

 
Praveen Kusuma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I want to invoke a managed bean method from a Servlet,
How to call that method? Can we acheive this using the Faces context Object?
Can anyone help me on giving Code Snippet for this.

Thanks in advance...
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to call it from a Servlet ?

Can you please explain what are you trying to do ?
 
Praveen Kusuma
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to implement AJAX in my portlet application,
On tab action I am calling a JS funtion there I am going to call a Servlet , from there I want to call my Managed Bean method.
I am doing this to control the page refresh(flickering),I am not sure even if we call the managed bean method from Servlet the page refresh(flickering) will control or not.

Thanks in Advance.
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the scope of your managed bean ?

Let the scope be application, and then inside your Servlet, get a reference to the ServletContext so you can get that managed bean from.

Try this and let me know please ...

Best of luck ...
 
A. Dusi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used code as given in this link and it worked for me. Hope it helps you too.
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only thing "magic" about managed beans is that the JSF framework constructs and initializes them. They're perfectly ordinary JavaBeans. If you give a managed bean session scope, you can pull it from the Http Session object and use it just like any other session bean.

Since request-scope managed beans are constructed from the JSF servlet, it's a bit of a problem if you're dispatching some other servlet instead. However, there's no law that says your own servlet can't construct request-scope JabvaBeans - the only thing is that you won't get the managed initializations (if any) done for you. You'll have to do the initializations yourself. Either that or find a way for the JSF servlet to forward to your own servlet after it has gone through the construction phase.
 
Jagadesh Rangaswamy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey as said earlier cases you can able to access by loading faces context from the faces context factory.


ex:

TestHandler = (TestHandler) request.getSession().getAttribute("TestHandler");

TestHandler.getXXX();
TestHandler .save();


if it helps.. let me knoww
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!