I've the following context:
a xhtml page, like this one:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>My Event</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<body>
<f:event listener="#{filterEventCreator.check}" type="preRenderView" />
...
This is the filterEventCreator:
public void check(ComponentSystemEvent event) {
if(amIComingFromDispatcher()){
SYSO_Testing.syso("FilterEventCreator in this case, everything it's ok");
sessionUtility.setNotComingFromDispatcher();
}
else{
try {
SYSO_Testing.syso("I'm not coming from redirect");
sessionUtility.sessionLogout();
response.sendRedirect(errorPath);
}
catch (IOException ex) {
Logger.getLogger(FilterEventCreator.class.getName()).log(Level.SEVERE, null, ex);
}
}
private boolean amIComingFromDispatcher() {
if(this.loggedUser==null)return false;
return sessionUtility.getComingFromDispatcher();
}
Where the sessionUtility is the following one:
@Named
@SessionScoped
public class SessionUtility implements Serializable {
private String loggedUserName, loggedUserPassword;
private int errorCode, eventID;
private boolean error, comingFromDispatcher;
@PostConstruct
public void init() {
error = false;
comingFromDispatcher = false;
}
public void addUser(String username) {
loggedUserName = username;
SYSO_Testing.syso("User added in cache");
}
public String getLoggedUser() {
return loggedUserName;
}
public void sessionLogout() {
SYSO_Testing.syso("starting logout from Session bean");
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
loggedUserName = null;
error = false;
request.getSession().invalidate();
}
public void setError(int value) {
errorCode = value;
error = true;
}
public boolean isAnError() {
return error;
}
public int getError() {
return errorCode;
}
public void showedError() {
error = false;
}
public void setNotComingFromDispatcher() {
comingFromDispatcher = false;
}
public void setComingFromDispatcher() {
comingFromDispatcher = true;
}
public boolean getComingFromDispatcher() {
return comingFromDispatcher;
}
What's happen is that if I connect directly to the xhtml page, the filter understand that i'm neither logged and neither coming with a redirect but when it tries to redirect the following error arises: Error Rendering View[/Error.xhtml] java.lang.NullPointerException
I debug this project and neither the response nor any variable except for the loggedUser are null. I'm grateful to anyone that can help me.