The entry point to my JSF application is EntryPoint.jsp. We are using JSF 1.2. The user may call EntryPoint.jsp with a number of different URL parameters. I woud like to parse these parameters, load up a session bean with some state, do all this before the page loads and either continue processing/display EntryPoint.jsp or foward/redirect to another page in the application. Can anyone recommend the best design for this?
I’ve tried in my EntryPoint.java backing bean (exception handling removed):
@PostConstruct
public void init() {
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
companyName = request.getParameter("companyCode");
//process parameters...
if (someCondition) {
FacesContext.getCurrentInstance().getExternalContext().dispatch("/other.jsp");
return;
}
}
but I get an IllegalStateException: Response already committed.
I’ve also tried
FacesContext.getCurrentInstance().getExternalContext().redirect("/other.jsp");
but also get an IllegalStateException (with no message). Clearly this isn’t the appropiate way or place to do this. Can anyone recommend a better way to achieve what I am looking for?
This post seems to suggest a servlet filter might be a good choice. If so, would the session scope JSF backing bean be available in the servlet filter?
This is indeed not going to work for JSF 1.x. As you found in the other question, a
Filteris indeed a more appropriate place for this job. This answer has not been changed since then. A session scoped JSF managed bean is stored in theHttpSessionwith the managed bean name as session attribute name. So yes, it’s accessible in theFilter. Even more, theFiltercould precreate it and put it in the session. JSF will then use it instead of autocreating one.