I recently migrated my JSF application to Spring Boot 3 and Jakarta EE, and now I’m experiencing an issue where my preRenderView() method gets called twice per page load, in different threads. This is causing problems when trying to show FacesMessages on the page, as they get loaded into the FacesContext MessageList the first time, but then preRenderView is called again and the messages are lost.
I call the preRenderView method in my AbstractController from all controller JSF pages like this inside a <ui:define>
element that I insert into the template.
<f:event listener="#{controller.preRenderView()}" type="preRenderView" />
My preRenderView calls this method:
public void showMessages()
{
if (FacesContext.getCurrentInstance().getResponseComplete())
{
return;
}
final var messages = Optional
.ofNullable((List<FacesMessage>) FacesContext.getCurrentInstance()
.getExternalContext()
.getSessionMap()
.remove("flash.messages"))
.orElse(Collections.emptyList());
for (final FacesMessage message : messages)
{
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
All my controllers have the Spring Context @Scope("view")
annotation.
FacesContext.getCurrentInstance().getResponseComplete()
and FacesContext.getCurrentInstance().isPostback()
are always false, so I couldn't fix it using these checks.
Before the upgrade to Spring Boot 3 this code worked just fine.