Re: View object not expiring for h:link with f:param when PrettyFaces enabled

Splash Forums PrettyFaces Users View object not expiring for h:link with f:param when PrettyFaces enabled Re: View object not expiring for h:link with f:param when PrettyFaces enabled

#20478

Turkish Delight
Participant

I doubt it has to do with the h:link, because this still happens if I just enter the URLs into the address bar, regardless if I use the pretty /view/12345 syntax or the standard /view.jsf?id=12345 syntax. Here it is anyway:

<h:link outcome="view" value="#{book.name}">

<f:param name="id" value="#{book.id}" />

</h:link>

The contents of the pretty-config:

<url-mapping id="public-view-book">

<pattern value="/view/#{ id }" />

<view-id>/view.jsf</view-id>

<query-param name="id">#{id}</query-param>

</url-mapping>

The target view:

<!-- ... -->

<f:metadata>

<f:viewParam name="id" value="#{bookSessionBean.bookId}" />

<f:event type="preRenderView" listener="#{bookSessionBean.loadBookByIdForPublic}" />

</f:metadata>

<!-- ... -->

<c:if test="#{empty bookSessionBean.book}">

<!-- "book not found" -->

</c:if>

<c:if test="#{not empty bookSessionBean.book}">

<!-- display book summary -->

</c:if>

The problem is that the c:if tests are being evaluated based on the last value of “empty bookSessionBean.book”, not based on the current one. I.e., if I go to /view/123invalid_id, then navigate to /view/12345, I still get the “book not found” block built instead of the summary for book #12345. If I reload the page, then I get the summary for #12345. If I then go to /view/67890, I get the summary for book #67890 right away (because the same component tree is used), but if I then go back to /view/123invalid_id without then reloading, it tries to display the summary for a non-existent book, causing a NullPointerException instead of displaying the “book not found” block.