留言板

Display Dynamic Message along with Session Success Message

Ramakrishnan Sinduja,修改在7 年前。

Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

Liferay Master 帖子: 722 加入日期: 10-8-5 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

Junior Member 帖子: 85 加入日期: 16-7-12 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
Thank You
Mrs Sindhu,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

Junior Member 帖子: 85 加入日期: 16-7-12 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
Ok, thanks Gaurav.

I will try as you have mentioned.
Mrs Raghavan,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

Junior Member 帖子: 85 加入日期: 16-7-12 最近的帖子
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,修改在7 年前。

RE: Display Dynamic Message along with Session Success Message

New Member 帖子: 19 加入日期: 16-7-28 最近的帖子
Hi Gaurav,

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

Thanks for your response.

Regards,
Mrs.Raghavan.