Search code examples
javajakarta-eejsf-2myfacesmojarra

Apache MyFaces JSF2.0 bug: getStateHelper().put doesn't save anything?


MyFaces seems to be ignoring my call to getStateHelper.put() in this component:

public class BFTableComponent extends UINamingContainer {
...
    private void setCurrentPageNumber(int currentPageNumber) {
        getStateHelper().put(PropertyKeys.currentPageNumber, currentPageNumber);
    }

    public int getCurrentPageNumber() {
        return (Integer) getStateHelper().eval(PropertyKeys.currentPageNumber, 0);
    }

public void nextPage() {
    setCurrentPageNumber(getCurrentPageNumber() + 1);
    updateCurrentPage();
}

public void previousPage() {
    setCurrentPageNumber(getCurrentPageNumber() - 1);
    updateCurrentPage();
}

...
}

As you can see, when the frontend component calls nextPage, the goal is to advance the page number by one. However, when running this in MyFaces, the eval() call will work for the immediate request lifecycle, but the next request, it will return 0. If I put null instead of 0, I gett an NPE.

The pageNumber state needs to carry for the lifetime of the component, not just the current request. What am I doing wrong? This code runs fine under Mojarra, but not in MyFaces.


Solution

  • Turns out it actually was a bug somewhere in MyFaces. I was running this in Apache TomEE beta2. It included MyFaces 2.1.2. I replaced the jars with 2.1.7 and the problem fixed itself.

    Thanks for looking!