Is it possible to use a JSF (PrimeFaces) page in the following fashion ? :
- external application (not JSF-based) does an HTTP GET with URL parameters
- JSF page reads those parameters (e.g. as described here) and invokes a backing bean business method, without rendering anything to the user's browser
- The user is transparently sent to a page corresponding to the navigation outcome of the backing bean method invoked in step 2.
In other words, the PrimeFaces page of step 2 is involved only for the side effect of calling the backing-bean business method and is never displayed. The user after clicking on a link on the external application of step 1 lands in the page of step 3.
Use <f:viewParam>
to set GET parameters as bean properties and use <f:event>
to execute a bean action and use NavigationHandler
to perform navigation programmatically.
View:
<f:metadata>
<f:viewParam name="foo" value="#{bean.foo}" />
<f:viewParam name="bar" value="#{bean.bar}" />
<f:event type="preRenderView" listener="#{bean.action}" />
</f:metadata>
Bean:
public void action() {
// ...
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler navigationHandler = context.getApplication().getNavigationHandler();
navigationHandler.handleNavigation(context, null, "outcome");
}
Note that, depending on the concrete functional requirement, JSF might not necessarily be the right tool for the job. I'd investigate if you couldn't better use a servlet filter or even a plain servlet for the purpose.
See also:
- What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?
- Hit a bean method and redirect on a GET request