Reputation: 2003
I have a page with sendmail functionality. It s a simple richtextfield and when pressing send button, a mail is send with the textfield as body. This works. But I want to display a message 'mail send' so that the users sees the mail has been send. I can do it by executing the following:
addFacesMessage(FacesMessage.SEVERITY_INFO, getMsg("common_mail_send_ok") + " (" + toAddresses[0] + ")");
This message is displayed in the field. But this is on a totally different part of my page so I want to display the message in the field associated to the richtextfield. I tried teh following, but I don't get any message and I don't get an error.
This is my jsf
<h:messages id="mainmessages" globalOnly="true" styleClass="info" errorClass="error" />
...
<p:fieldset id="emailPanel" toggleable="true" collapsed="true" style="width:800px;">
<h:outputText value="#{msg.workorderdetail_message}:"/>
<p:editor id="mailbody" value="#{workOrderDetail.message}" widgetVar="editor" width="500" height="200"/>
<p:commandButton styleClass="button" process="emailPanel" update="emailPanel mailmessage mainmessages" value="#{msg.workorderdetail_sendemail}" actionListener="#{workOrderDetail.sendMail}" onstart="busyPopup.show()" oncomplete="busyPopup.hide()"/>
<h:message id="mailmessage" for="mailbody" styleClass="info" errorClass="error"/>
</p:fieldset>
and this is my class
public String sendMail() throws Exception {
....
mailer.send();
FacesContext.getCurrentInstance().addMessage(
"detail:wodetail:mailbody",
new FacesMessage(FacesMessage.SEVERITY_INFO,
getMsg("common_mail_send_ok") + " (" + toAddresses[0] + ")", getMsg("common_mail_send_ok") + " ("
+ toAddresses[0] + ")"));
addFacesMessage(FacesMessage.SEVERITY_INFO, getMsg("common_mail_send_ok") + " (" + toAddresses[0] + ")");
...
}
I don't know what I'm doing wrong. I think this used to work in the past, and I even sometimes while developing got the message saying some error message was added to the que, but was unable to display (because the message field was not rerendered) But now(newer version of prime3.4.2) I get nothing.
Upvotes: 0
Views: 3166
Reputation: 31
Add following codes. It will helps for you
<p:messages showDetail="true" />
Thanks
Upvotes: 0
Reputation: 1109865
This will happen when the message client ID detail:wodetail:mailbody
is wrong. For starters who haven't memorized the JSF NamingContainer
components so that they could figure it by just looking at the JSF source code, the easiest way to figure the right client ID is looking into the generated HTML output. Open the page in browser, rightclick and View Source, look at the HTML output generated by <p:editor>
and use the HTML element id
of the top level HTML element as JSF client ID.
Further, another probable cause is that the message component is not updated on ajax requests. For that you need to use PrimeFaces autoUpdate="true"
or just to specify the message component's client ID in ajax update. In your particular code example, this seems to be fine already. So the only probable cause left is simply a wrong message client ID.
Upvotes: 3