最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JSF preRenderView() Called Twice in Different Threads After Migrating to Spring Boot 3 - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论