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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Calling a servlet from a backing bean" Watch "Calling a servlet from a backing bean" New topic
Author

Calling a servlet from a backing bean

Lance Cash
Greenhorn

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 is...it doesn't work! I don't know if it is an icefaces issue or what, but I get the following error:


java.io.IOException: Cannot dispatch on XMLHTTP request.


I'm hoping someone out there will have other ideas, and please...no 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: 4967

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


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Lance Cash
Greenhorn

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

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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Calling a servlet from a backing bean
 
Similar Threads
How to redirect from backing bean to servlet ?
Return PDF via Response Stream.
getter method error handling
f:selectitems issue in jsf
How can I optimize this for JSF?