aspose file tools*
The moose likes JSF and the fly likes Calling a servlet from a backing bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Calling a servlet from a backing bean" Watch "Calling a servlet from a backing bean" New topic

Calling a servlet from a backing bean

Lance Cash

Joined: Oct 19, 2009
Posts: 17
I've been poking around all over the place looking for how one can invoke a servlet from within a backing bean and have come up empty. The most promising code I found was:

The problem doesn't work! I don't know if it is an icefaces issue or what, but I get the following error: Cannot dispatch on XMLHTTP request.

I'm hoping someone out there will have other ideas, and suggestions on how to better design this thing. It's gotta stay a servlet! This isn't the only place this thing gets used. I am open, however to other suggestions on how to call the servlet. Originally, it was being invoked via an outputLink, but now it needs to perform some action as well. I realize that I could create a hidden input button and invoke it with some javascript, but that just seems awfully hokie to me. I would like to present my boss with a more elegant solution than that.

Thanks in advance, everyone. Lance.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

What is the role of the Servlet in this case? Does it perform business logic exclusively, or does it generate markup for display?
Lance Cash

Joined: Oct 19, 2009
Posts: 17
It is generating a pdf report of system activity.
Lance Cash

Joined: Oct 19, 2009
Posts: 17
Alright, well...I figured out how to call the servlet from the backing bean, but it ended up not helping me out. This particular servlet needs to be invoked from the right context in order to execute properly so that it can grab stuff like the user state from the session. When calling it from a bean as I did, that stuff isn't instantiated. But for anyone that may be interested in how to do this in the future, here you go:

I ended up having to call on javascript to the rescue after all via a hidden button invoked by the onclick() method of the outputLink tag.

Thanks anyways, guys.
I agree. Here's the link:
subject: Calling a servlet from a backing bean
Similar Threads
getter method error handling
How to redirect from backing bean to servlet ?
Return PDF via Response Stream.
How can I optimize this for JSF?
f:selectitems issue in jsf