I\'ve been having this trouble for a couple of days. hopefully this is cleaner and someone who\'s done this before can help me out!
I\'m building a webApp with JSF 2
First of all, the navigation rule is for JSF only. They can't help you to navigate to a servlet.
The navigation rules in faces-config are redundant in JSF2.0. They are implicitly handled by JSF, based on the value (outcome) returned by an action method. "?faces-redirect=true"
can be attached to the end of the outcome for redirection.
I don't know what your functional requirement is. You are trying to mix JSF and servelts, which is not a very good idea.
<h:commandButton id="reportButton" action="reportPdf"
The value of the action
attribute must be a method expression that resolves to a method in some JSF managed bean. e.g. action="#{controllerBean.axnMethod()}"
.
When the axnMethod()
is called, one option is to redirect from there to the servlet. The is something as follows:
FacesContext.getCurrentInstance().getExternalContext().redirect("url");
Or, requirement is just to invoke the servlet then on the view, just put a link with the url that invokes the servlet.
JSF is executed within the Faces servlet and with the standard navigation you can only navigate to jsf views. To open a servlet use instead. Another option is to avoid using a servlet and to serve your pdf file from an action method like it's described here: http://www.winstonprakash.com/articles/jsf/file_download_link.htm