Forums de discussion

Display Dynamic Message along with Session Success Message

Ramakrishnan Sinduja, modifié il y a 7 années.

Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Hi,

I want to display message as"Email has been successfully sent to X recipients" and the X is the email count.Could anybody tell me how to achieve this.

Regards,
Sindhu R
thumbnail
Pankaj Kathiriya, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

Liferay Master Publications: 722 Date d'inscription: 05/08/10 Publications récentes
You can use LanguageUtil utility class to achieve this.

e.g.
language-key=Email has been successfully sent to {0} recipients

LanguageUtil.format(locale, "language-key", placeholdervalue)


Here, placeholdervalue will be custom count.
Ramakrishnan Sinduja, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Hi Pankaj,

Thanks for your response.

Just correct me If I am wrong, the below line needs to be set in action class and language-key=Email has been successfully sent to {0} recipients has to set in Language.properties is it???

LanguageUtil.format(locale, "language-key", placeholdervalue).

Appreciate your response.

Regards,
Sindhu R
thumbnail
Gaurav Jain, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

Junior Member Publications: 85 Date d'inscription: 12/07/16 Publications récentes
Hi Mrs Sindhu,

Mrs Sindhu:

LanguageUtil.format(locale, "language-key", placeholdervalue).



This line is to be set into jsp file where you want to display dynamic message.

Regards,
Gaurav
Mrs Sindhu, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Thank You
Mrs Sindhu, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Hi Gaurav,

As mentioned I have set the LanguageUtil.format(locale, "mailSendKey", Message); in my JSP page where I want to display. But I am unable to see the expected message .
Please advice.

Regards,
Sindhu R
thumbnail
Gaurav Jain, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

Junior Member Publications: 85 Date d'inscription: 12/07/16 Publications récentes
Hi Mrs Sindhu,

This should work, you must be missing something. But if not, you can try this also in you jsp:

<liferay-ui:success key="mailSendKey" message="<%=LanguageUtil.format(locale, &quot;Email has been successfully sent to {0} recipients&quot;, mailCount) %>" />


Here mailCount is that dynamic value you want to display as part of message.

One more thing, do not forget to set this key into session message from your controller class as:

SessionMessages.add(actionRequest, "mailSendKey");


Regards,
Gaurav
Mrs Raghavan, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Ok, thanks Gaurav.

I will try as you have mentioned.
Mrs Raghavan, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Hi Gaurav,

I am able to achieve this by
<liferay-ui:success key="mailSendKey" message='<%=LanguageUtil.format(locale, "Email has been successfully sent to {0} recipients", 3) %>' />

but here I have hard coded the mail count as 3, and I have stored the mailcount value in session variable in controller class.

If I change like below its not working, Please advice.

Integer intEmailCount = (Integer) session.getAttribute("EmailCount");

<%if(intEmailCount!=null){
<liferay-ui:success key="mailSendKey" message='<%=LanguageUtil.format(locale, "Email has been successfully sent to {0} recipients", 3) %>' />
<%}%>
Mrs Raghavan, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Hi Gaurav,

I have managed to solve the issue and its working as expected.I have used your below syntax.

<liferay-ui:success key="mailSendKey" message='<%=LanguageUtil.format(locale, "Email has been successfully sent to {0} recipients", mailCount) %>' />

And mailCount , I am setting in controller class.Work Perfect.

Thanks a lot for timely help.

Regards,
Sindhu R
thumbnail
Gaurav Jain, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

Junior Member Publications: 85 Date d'inscription: 12/07/16 Publications récentes
Hi Mrs Raghavan,

One more thing I would like to let you know that you really do not need to hard code any string in success message as exemplary shown by me in:
<liferay-ui:success key="mailSendKey" message="<%=LanguageUtil.format(locale, &quot;Email has been successfully sent to {0} recipients&quot;, mailCount) %>" />


Instead create a key in language.properties file as:
mailSendKey=Email has been successfully sent to {0} recipients


And use it in jsp as:

<liferay-ui:success key="mailSendKey" message="<%=LanguageUtil.format(pageContext, &quot;mailSendKey&quot;, mailCount) %>" />


Note: In this case pageContext has been used instead of locale

Regards,
Gaurav
Mrs Raghavan, modifié il y a 7 années.

RE: Display Dynamic Message along with Session Success Message

New Member Publications: 19 Date d'inscription: 28/07/16 Publications récentes
Hi Gaurav,

Ok Noted, I will try to implement the below changes .

Thanks for your response.

Regards,
Mrs.Raghavan.