Pregunta

Here's the scenario. In my managed bean, I create a new FacesMessage object and add it to the FacesContext, without associating it with any UI component, like so:

FacesContext context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
message.setSummary("Hi there!");
context.addMessage(null, message);

In my xhtml page, I output my message like so:

<h:messages id="someId" globalOnly="true" showSummary="true" showDetail="false" styleClass="startUpMessages"/>

However, the generated html displays the summary of the message twice, like so:

<ul id="mainForm:someId" class="startUpMessages"><li>   Hi there! </li><li> Hi there! </li></ul>
<ul id="javax_faces_developmentstage_messages" title="Project Stage[Development]: Unhandled Messages"></ul>

Can anyone explain this behaviour?

¿Fue útil?

Solución

Turns out this issue was caused by an oversight in a phase listener in the application, that wasn't mentioned in the question.

This phase listener was designed to solve an issue with persisting FacesMessages across two adjacent requests, in one particular instance of the application. It would store all of the FacesMessages that were created in a request scoped bean into the session temporarily.

However, the phase listener was mistakingly implemented to execute during every request. So FacesMessages that were created in session scoped beans (like the one in question) ended up being duplicated, which explains why I was seeing the summary of the message displayed twice.

Otros consejos

Try to change your Web.xml.
Change PROJECT_STAGE from Development to Production

<!-- Web application context parameters -->
<context-param>
    <description>One of Production, Development, UnitTest, SystemTest, Extension
        Default is Production.
    </description>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Production</param-value>
</context-param>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top