usertest
usertest

Reputation: 2272

simple jsf commandbutton work on every single page except home page

A Java EE 8/SE 8 web application in deployement runnnig on Glassfish 5 build 25 both production and development, uses jsf 2.3. users create accounts and login. there is a 'logout' button for loging out.

Problem: 'logout' button works as expected everywhere on the website. EXCEPT home page (example.com) & (example.com/home.xhtml). the problem does not exists on my local computer. only in production (example.com).

So I have a template called : index.xhtml . all pages use it, including home.xhtml:

<ui:composition template="index.xhtml">
    <ui:define name="top-bar">
        <c:if test="#{request.remoteUser ne null}">
            <h:form ><h:commandButton value="Log out" action="#{registerAdvanced.logout}"/></h:form>
        </c:if>
    </ui:define>

and

@Named
@RequestScoped
public class RegisterAdvanced extends BaseBacking implements Serializable {
    public String logout() {
        try {
            getRequest().logout();
            getContext().getExternalContext().getSessionMap().remove("user");
            return REDIRECT_PAGE;
        } catch (ServletException ex) {
            return REDIRECT_PAGE;
        }
    }
}

Users login & logout fairly easily until I noticied that clicking on logout on the home page (home.xhtml) prints a null pointer exception AND redirect to 404 error page.

[[/home.xhtml @450,77 value="#{passesTestBean.displayPassSummaryList}": java.lang.NullPointerException
javax.el.ELException: /home.xhtml @450,77 value="#{passesTestBean.displayPassSummaryList}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:119)
at com.sun.faces.facelets.component.UIRepeat.getValue(UIRepeat.java:314)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:256)
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:507)
at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:557)
at com.sun.faces.facelets.component.UIRepeat.processDecodes(UIRepeat.java:861)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1258)....

part of jsf where there is a call to value="#{passesTestBean.displayPassSummaryList}" is 100% seperate to logout and PassesTestBean CDI is request scope.

so the problem is SOMEHOW when I click on logout button. PassesTestBean is called for no reason and not since jsf must Initialize (since Request Scoped). it ends up returning null.

Now remember this only happens in: production at example.com AND only home page of all pages.

I'm thinking of writing a page only for loging out: has a log out button only.

Upvotes: -1

Views: 134

Answers (1)

Armen Arzumanyan
Armen Arzumanyan

Reputation: 2063

Check for null pointer exception

getRequest().logout(); //here
getContext().getExternalContext().getSessionMap().remove("user");//here

Upvotes: -1

Related Questions