留言板

SessionMessages

liferay developer,修改在14 年前。

SessionMessages

New Member 帖子: 12 加入日期: 10-3-30 最近的帖子
Hi there,

Need to customize login portlet in Liferay 5.2.3 working with the extension environment
One of the things I need to do is to display a session message or an error message like this ones:





For the error message (the red ones) I did it like this and it is working fine:

in processAction method of the Action:

if (condition) {
throw new MarketingCustomAttributeAlreadyAssignedException();
}

and in the correspondant jsp:

<liferay-ui:error exception="<%= MarketingCustomAttributeAlreadyAssignedException.class %>" message="marketing.error.custom-attribute-already-asigned" />

and that is working fine


But for the green ones what I tried after look at the source code is this but does not work:

in processAction method of the Action:

SessionMessages.add(actionRequest, "mensaje-de-prueba");

in the correspondant jsp:

<c:if test='<%= SessionMessages.contains(request, "test-message-01") %>'>
<span class="portlet-msg-info">
<liferay-ui:message key="test-message-01" />
</span>
</c:if>

in Language-ext.properties:

test-message-1=Hello

But nothing is displayed

Any help? Or another way to do it?

thanks in advance
thumbnail
Wilson Man,修改在14 年前。

RE: SessionMessages

Liferay Master 帖子: 581 加入日期: 06-6-21 最近的帖子
liferay developer:
in processAction method of the Action:

SessionMessages.add(actionRequest, "mensaje-de-prueba");

in the correspondant jsp:

<c:if test='<%= SessionMessages.contains(request, "test-message-01") %>'>
<span class="portlet-msg-info">
<liferay-ui:message key="test-message-01" />
</span>
</c:if>


those should be the same.
liferay developer,修改在14 年前。

RE: SessionMessages

New Member 帖子: 12 加入日期: 10-3-30 最近的帖子
Thanks but that was not the problem. Yes of course the key should be the same, that was just a copy paste error when copy here but that is not the reason.

Anyway I found the reason that is:

SessionMessages.add(actionRequest, "test-message-01");

It shoud not be actionRequest but the request from HttpServletRequest Class that it can be obtained from actionRequest like this:

HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(
actionRequest);

And then doing this:

SessionMessages.add(servletRequest, "test-message-01");

is working fine

but thanks
thumbnail
Wilson Man,修改在14 年前。

RE: SessionMessages

Liferay Master 帖子: 581 加入日期: 06-6-21 最近的帖子
i was able to use actionRequest to set the Session Message.
(disregard my previous post about private-request-attribute since that wouldn't help).
I'll let you know when i find the solution so you don't need to touch the HttpServletRequest directly.
Riley Pickerl,修改在10 年前。

RE: SessionMessages

Junior Member 帖子: 50 加入日期: 13-1-10 最近的帖子
Hi there I am trying to set session messages from a portlet in vaadin. I am having no problem setting and getting the message, however I do not have any jsp so I am not sure how to make the liferay UI display the messages on request. Is there a way to tell liferay to display the sessionmessages in the ui from java and not jsp?

Thanks
thumbnail
David H Nebinger,修改在10 年前。

RE: SessionMessages

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
Hey, Riley, the Vaadin portlet you create is totally responsible for the UI. Liferay will not inject elements into your UI, so you're going to have to take care of this yourself. That said, you can add the Liferay styles to labels to get them to render in the green, yellow, and red colors.
Riley Pickerl,修改在10 年前。

RE: SessionMessages

Junior Member 帖子: 50 加入日期: 13-1-10 最近的帖子
Darn, I was fearing that to be the answer. It seems strange that there is no API call that can trigger showing the Liferay messages.
Thanks for the quick response David!
thumbnail
David H Nebinger,修改在10 年前。

RE: SessionMessages

Liferay Legend 帖子: 14916 加入日期: 06-9-2 最近的帖子
Well, it's implemented using the Liferay tag library. You need to manually insert them into your JSP pages, too. There's nothing automatic about it...

If you were doing JSF, ZK, or any other framework you'd be left to rendering it manually, too...