Rectangle 27 0

jsf How to display FacesMessage from PostConstruct method of a request scoped bean?


<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<h:head></h:head>
<body>
<h:outputText value="#{backingBean.emptyString"/>

...

</body>
</html>
@ManagedBean
@RequestScopped
public class BackingBean {
    public String getEmptyString { return ""; }
}

I was experiencing the same issue on WebSphere 7 with MyFaces JSF 2.1.

It appears as though WebSphere is flushing the buffer too early, so that the messages tag is rendered prior to the @PostConstruct method completing. I have not as yet found a way to alter WebSphere's behavior however by placing a getter-method in the managed bean to return an empty string and use a h:ouputText tag to use the value I now have a page which renders my messages.

Note
Rectangle 27 0

jsf How to display FacesMessage from PostConstruct method of a request scoped bean?


**<h:messages />**
<h:form>
    <h:inputText value="#{myBean.name}" />
</h:form>
<h:form>
    <h:inputText value="#{myBean.name}" />
</h:form>
**<h:messages />**

I solved the same problem by putting the messages after the first declaration of the bean that is expected to produce the message you want to be shown. So in your example above instead of having this:

Note