<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Success or Error Messages are not displaying</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111251383" />
  <subtitle>Success or Error Messages are not displaying</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111251383</id>
  <updated>2026-04-04T14:58:30Z</updated>
  <dc:date>2026-04-04T14:58:30Z</dc:date>
  <entry>
    <title>RE: Success or Error Messages are not displaying</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111257842" />
    <author>
      <name>Kyle Joseph Stiemann</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111257842</id>
    <updated>2018-10-19T17:28:03Z</updated>
    <published>2018-10-19T17:28:03Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi Ehtisham,&lt;br&gt;Your &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;BillTypeBean.save()&lt;/span&gt; method is being called correctly, but the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;p:message&lt;/span&gt; component cannot render the message you added because you added it under the wrong id. &lt;a href="https://javaserverfaces.github.io/docs/2.2/javadocs/javax/faces/context/FacesContext.html#addMessage(java.lang.String,%20javax.faces.application.FacesMessage%29"&gt;&lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;FacesContext.addMessage()&lt;/span&gt;&lt;/a&gt; takes the components &lt;strong&gt;fully qualified&amp;nbsp;client id&lt;/strong&gt; not just the component's id. In a portlet environment, the client id includes the portlet namespace.&lt;br&gt;&lt;br&gt;​​​​​​​There are multiple ways you can fix this issue in your code:&lt;br&gt;&lt;br&gt;&lt;ol style="list-style: decimal outside;" start="1"&gt;&lt;li&gt;Make the error message global and change the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;p:message&lt;/span&gt; to &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;p:messages globalOnly="true"&lt;/span&gt; (this may not be appropriate for your use case).&lt;/li&gt;&lt;li&gt;Obtain the client id from the component before adding the message:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
UIComponent component = viewRoot.findComponent("form:name");
String clientId = component.getClientId(context);
facesContext.addMessage(clientId, new FacesMessage(message));&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;Concatenate the client id for the component yourself:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().encodeNamespace(":name");
String clientId = context.getExternalContext().encodeNamespace(":name");
facesContext.addMessage(clientId, new FacesMessage(message));&lt;/code&gt;&lt;/pre&gt;&lt;br&gt; Note that while testing I discovered that PrimeFaces components and default HTML (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;h:&lt;/span&gt;) components use different values for the client id. &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;p:inputText&lt;/span&gt; did not include the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;":form"&lt;/span&gt; id (from the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;&amp;lt;h:form&amp;gt;&lt;/span&gt; &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;NamingContainer&lt;/span&gt; parent) while &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;h:inputText&lt;/span&gt; &lt;strong&gt;did&lt;/strong&gt; include the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;":form"&lt;/span&gt; id. So if you wanted to get the client id for an &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;h:inputText&lt;/span&gt;, you would need to use &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;context.getExternalContext().encodeNamespace(":form:name")&lt;/span&gt;. Because of these kinds of issues, it's safer to use method #1 or #2 to deal with this issue.&lt;/li&gt;&lt;/ol&gt;While testing this code, I also noticed that you are performing validation in the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;save()&lt;/span&gt; action listener. You might want to consider adding &lt;a href="https://www.primefaces.org/docs/vdl/6.2/core/primefaces-p/inputText.html#validator"&gt;a custom validator (&lt;span style="font-family: &amp;quot;Courier New&amp;quot;"&gt;validator="my.custom.Validator"&lt;/span&gt;)&lt;/a&gt; to perform validation instead.&lt;br&gt;&lt;br&gt;Please let us know if that fixes your issue.&lt;br&gt;&lt;br&gt;- Kyle&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Kyle Joseph Stiemann</dc:creator>
    <dc:date>2018-10-19T17:28:03Z</dc:date>
  </entry>
  <entry>
    <title>Success or Error Messages are not displaying</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111251382" />
    <author>
      <name>Ehtisham Zahid</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111251382</id>
    <updated>2018-10-19T10:33:38Z</updated>
    <published>2018-10-19T10:33:38Z</published>
    <summary type="html">Hi, &lt;br /&gt;&lt;br /&gt;Success and Error messages are not displaying while validation in bean.&lt;br /&gt;If we submit empty form and the field is required true then the error message will appear but if i try to check duplicate or any other validation from bean and try to show error message on xhtml page, It doesnt display message.&lt;br /&gt;&lt;br /&gt;I using Liferay 7.1 with primefaces 6.2&lt;br /&gt;&lt;br /&gt;build.graddle:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #b22222"&gt;apply plugin: &amp;#39;war&amp;#39;&lt;br /&gt;&lt;br /&gt;repositories {&lt;br /&gt;     mavenCentral()&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;dependencies {&lt;br /&gt;    compile group: &amp;#39;org.primefaces&amp;#39;, name: &amp;#39;primefaces&amp;#39;, version: &amp;#39;6.2&amp;#39;&lt;br /&gt;    compile group: &amp;#39;com.liferay.faces&amp;#39;, name: &amp;#39;com.liferay.faces.bridge.ext&amp;#39;, version: &amp;#39;5.0.3&amp;#39;&lt;br /&gt;    compile group: &amp;#39;com.liferay.faces&amp;#39;, name: &amp;#39;com.liferay.faces.bridge.impl&amp;#39;, version: &amp;#39;4.1.2&amp;#39;&lt;br /&gt;    compile group: &amp;#39;log4j&amp;#39;, name: &amp;#39;log4j&amp;#39;, version: &amp;#39;1.2.14&amp;#39;&lt;br /&gt;    runtime group: &amp;#39;org.glassfish&amp;#39;, name: &amp;#39;javax.faces&amp;#39;, version: &amp;#39;2.2.18&amp;#39;&lt;br /&gt;    providedCompile group: &amp;#39;javax.faces&amp;#39;, name: &amp;#39;javax.faces-api&amp;#39;, version: &amp;#39;2.2&amp;#39;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;bean :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #b22222"&gt;package com.ba.bean;&lt;br /&gt;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;&lt;br /&gt;import javax.annotation.PostConstruct;&lt;br /&gt;import javax.faces.application.FacesMessage;&lt;br /&gt;import javax.faces.bean.ManagedBean;&lt;br /&gt;import javax.faces.bean.ViewScoped;&lt;br /&gt;import javax.faces.context.FacesContext;&lt;br /&gt;&lt;br /&gt;@ManagedBean(name = &amp;#34;billTypeBean&amp;#34;)&lt;br /&gt;@ViewScoped&lt;br /&gt;public class BillTypeBean implements Serializable {&lt;br /&gt;&lt;br /&gt;    private static final long serialVersionUID = 1L;&lt;br /&gt;&lt;br /&gt;    private String name = null;&lt;br /&gt;&lt;br /&gt;    @PostConstruct&lt;br /&gt;    public void init() {&lt;br /&gt;        name = new String();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void save() {&lt;br /&gt;        FacesContext context = FacesContext.getCurrentInstance();&lt;br /&gt;        if (name != null || name.equals(&amp;#34;asd&amp;#34;)) {&lt;br /&gt;            context.addMessage(&amp;#34;name&amp;#34;,&lt;br /&gt;                    new FacesMessage(FacesMessage.SEVERITY_ERROR, &amp;#34;Please Fill&amp;#34; + &amp;#34; &amp;#34; + &amp;#34;Name&amp;#34;, null));&lt;br /&gt;            &lt;br /&gt;        } else {&lt;br /&gt;            name = &amp;#34;dsa&amp;#34;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getName() {&lt;br /&gt;        return name;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void setName(String name) {&lt;br /&gt;        this.name = name;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;xhtml page :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #b22222"&gt;&amp;lt;?xml version=&amp;#34;1.0&amp;#34;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;f:view xmlns=&amp;#34;http://www.w3.org/1999/xhtml&amp;#34;&lt;br /&gt;    xmlns:f=&amp;#34;http://xmlns.jcp.org/jsf/core&amp;#34;&lt;br /&gt;    xmlns:h=&amp;#34;http://xmlns.jcp.org/jsf/html&amp;#34;&lt;br /&gt;    xmlns:p=&amp;#34;http://primefaces.org/ui&amp;#34;&lt;br /&gt;    xmlns:adm=&amp;#34;http://github.com/adminfaces&amp;#34;&lt;br /&gt;    xmlns:ui=&amp;#34;http://xmlns.jcp.org/jsf/facelets&amp;#34;&amp;gt;&lt;br /&gt;    &amp;lt;h:head&amp;gt;&lt;br /&gt;        &amp;lt;h:outputStylesheet library=&amp;#34;css&amp;#34; name=&amp;#34;main.css&amp;#34; /&amp;gt;&lt;br /&gt;    &amp;lt;/h:head&amp;gt;&lt;br /&gt;    &amp;lt;h:body style=&amp;#34;background-color: #afbb8abd;&amp;#34;&amp;gt;&lt;br /&gt;&lt;br /&gt;        &amp;lt;h:form id=&amp;#34;form&amp;#34; prependId=&amp;#34;false&amp;#34; enctype=&amp;#34;multipart/form-data&amp;#34;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            &amp;lt;p:commandButton value=&amp;#34;Save&amp;#34; actionListener=&amp;#34;#{billTypeBean.save}&amp;#34;&lt;br /&gt;                update=&amp;#34;@form&amp;#34; icon=&amp;#34;fa fa-check&amp;#34; ajax=&amp;#34;false&amp;#34; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            &amp;lt;p:spacer width=&amp;#34;5&amp;#34; /&amp;gt;&lt;br /&gt;&lt;br /&gt;            &amp;lt;p:message for=&amp;#34;name&amp;#34;&amp;gt;&amp;lt;/p:message&amp;gt;&lt;br /&gt;&lt;br /&gt;            &amp;lt;p:separator&amp;gt;&amp;lt;/p:separator&amp;gt;&lt;br /&gt;            &amp;lt;div class=&amp;#34;ui-g ui-fluid&amp;#34;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                &amp;lt;div class=&amp;#34;ui-g-12 ui-lg-5 ui-xl-1&amp;#34;&amp;gt;&lt;br /&gt;                    &amp;lt;p:outputLabel value=&amp;#34;Name&amp;#34; for=&amp;#34;name&amp;#34;&amp;gt;&amp;lt;/p:outputLabel&amp;gt;&lt;br /&gt;                &amp;lt;/div&amp;gt;&lt;br /&gt;                &amp;lt;div class=&amp;#34;ui-g-12 ui-lg-7 ui-xl-11&amp;#34;&amp;gt;&lt;br /&gt;                    &amp;lt;p:inputText id=&amp;#34;name&amp;#34; value=&amp;#34;#{billTypeBean.name}&amp;#34; required=&amp;#34;true&amp;#34;&lt;br /&gt;                        maxlength=&amp;#34;100&amp;#34; requiredMessage=&amp;#34;Please fill Name&amp;#34;&amp;gt;&amp;lt;/p:inputText&amp;gt;&lt;br /&gt;&lt;br /&gt;                &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;            &amp;lt;/div&amp;gt;&lt;br /&gt;        &amp;lt;/h:form&amp;gt;&lt;br /&gt;    &amp;lt;/h:body&amp;gt;&lt;br /&gt;&amp;lt;/f:view&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;I am also attaching the .zip file.&lt;br /&gt;Kindly give some solution to this&lt;br /&gt;Thanks</summary>
    <dc:creator>Ehtisham Zahid</dc:creator>
    <dc:date>2018-10-19T10:33:38Z</dc:date>
  </entry>
</feed>
