掲示板

Bringing up the message form from my portlet

9年前 に Tomás Mena によって更新されました。

Bringing up the message form from my portlet

New Member 投稿: 7 参加年月日: 15/02/24 最新の投稿
I made a portlet that displays birthdays in the current and upcoming month for users in the scope group. Now, I would like to extend its functionality with a new feature, sending a message to the birthday user, but I can't seem to find the docs on the message portlet API.

Is there a way to include the 'send message' button from the contact center in my portlet? If not, is there a way to programmatically send a generic message?

Thanks
thumbnail
9年前 に Krzysztof Gołębiowski によって更新されました。

RE: Bringing up the message form from my portlet

Liferay Master 投稿: 549 参加年月日: 11/06/25 最新の投稿
Hello Tomás,
Liferay has a generic API for sending email's using shared Liferay configuration. It is quite a common case so there are lots of materials about that, for example: http://liferaytutorial.blogspot.com/2013/08/sending-mail-in-liferay.html or http://www.liferaysavvy.com/2013/11/send-mails-in-liferay-plugin-portlet.html.

Regards,
KG
9年前 に Tomás Mena によって更新されました。

RE: Bringing up the message form from my portlet

New Member 投稿: 7 参加年月日: 15/02/24 最新の投稿
Thank you for the reply!

I will check those links, but what I want to send is not an email. I want to send instead a private message that the birthday user would receive in the standard Social Office message inbox. Is this possible?
thumbnail
9年前 に Krzysztof Gołębiowski によって更新されました。

RE: Bringing up the message form from my portlet

Liferay Master 投稿: 549 参加年月日: 11/06/25 最新の投稿
You mean the Notification (the one in top-right corner) or a message from Private Message portlet?

KG
9年前 に Tomás Mena によって更新されました。

RE: Bringing up the message form from my portlet

New Member 投稿: 7 参加年月日: 15/02/24 最新の投稿
I meant the Private Message portlet.
thumbnail
9年前 に Jonathan Lee によって更新されました。

RE: Bringing up the message form from my portlet

New Member 投稿: 14 参加年月日: 10/09/16 最新の投稿
Hi Tomàs,

Yes, you can minic what Contact Center Portlet is doing, and include a send message button. Do you have access to the source code for Contact Center? You can follow how we create the button in user_toolbar.jsp

There are couple options you can do,

First

1) add th dependency for private-messaging portlet

required-deployment-contexts=\
    private-messaging-portlet


2) create a button to call a javascript methof to send message

<liferay-ui:icon cssClass="send-message" image="../aui/envelope" label="<%= true %>" message="message" onClick="Some Javascrpt method " url="javascript:;" />


the javascript method will look like


Liferay.provide(
		window,
		'<portlet:namespace />sendMessage',
		function() {
			<portlet:renderurl var="redirectURL" windowState="<%= LiferayWindowState.NORMAL.toString() %>" />

			var uri = '<liferay-portlet:renderurl portletname="<%= PortletKeys.PRIVATE_MESSAGING %>" windowstate="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="mvcPath" value="/new_message.jsp" /><portlet:param name="redirect" value="<%= redirectURL %>" /></liferay-portlet:renderurl>';

			uri = Liferay.Util.addParams('&lt;%= PortalUtil.getPortletNamespace(PortletKeys.PRIVATE_MESSAGING) %&gt;userIds=' + '&lt;%= user2.getUserId() %&gt;', uri) || uri;

			Liferay.Util.openWindow(
				{
					dialog: {
						centered: true,
						constrain: true,
						cssClass: 'private-messaging-portlet',
						destroyOnHide: true,
						height: 600,
						modal: true,
						plugins: [Liferay.WidgetZIndex],
						width: 600
					},
					id: '&lt;%= PortalUtil.getPortletNamespace(PortletKeys.PRIVATE_MESSAGING) %&gt;Dialog',
					title: '&lt;%= UnicodeLanguageUtil.get(pageContext, "new-message") %&gt;',
					uri: uri
				}
			);
		},
		['liferay-util-window']
	);


The most important part is the renderUR creation. The URL basically is pointing to the new_message.jsp for the private messaging portlet, where a user can create a new message

That should be it for the first option.

The second is to use the following actionURL as the form action when you submit your own form. If you have private-messaing-portlet deployed, you can create a actionURL that basically will invoke the sendMessage method in the PrivateMessagingPortlet.java class


<liferay-portlet:actionurl portletname="<%=  PortletKeys.PRIVATE_MESSAGING %>" var="sendMessageURL">
<portlet:param name="<%= ActionRequest.ACTION_NAME %>" value="sendMessage" />
<portlet:param name="userId" value="<%= userId %>" />
<portlet:param name="to" value="<%= recipientUserID %>" />
<portlet:param name="subject" value="<%= subject %>" />
<portlet:param name="body" value="<%= body %>" />
</liferay-portlet:actionurl>


you may look at new_message.jsp in the private messaging portlet to see what paremeter needs to be passed.
9年前 に Tomás Mena によって更新されました。

RE: Bringing up the message form from my portlet

New Member 投稿: 7 参加年月日: 15/02/24 最新の投稿
Yes, this is exactly what I want. I've got an issue though. I take it, the PortletKeys that I am to import is this one: "com.liferay.privatemessaging.util.PortletKeys". For some reason this resolves to a package and throws a JasperException at runtime.

For now, I hardcoded the portlet's key just to get past that, but now I am getting a JSP exception that points to this line:


var uri = '<liferay-portlet:renderurl portletname="1_WAR_privatemessagingportlet" windowstate="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="mvcPath" value="/new_message.jsp" /><portlet:param name="redirect" value="<%= redirectURL %>" /></liferay-portlet:renderurl>';


15:43:25,640 ERROR [RuntimePageImpl-59][PortletRequestDispatcherImpl:115] org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /view.jsp en línea 33____30: function() {__31: '<portlet:renderURL var="redirectURL" windowState="<%= LiferayWindowState.NORMAL.toString() %>" />'__32: __33: var uri = '<liferay-portlet:renderURL portletName="1_WAR_privatemessagingportlet" windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="mvcPath" value="/new_message.jsp" /><portlet:param name="redirect" value="<%= redirectURL %>" /></liferay-portlet:renderURL>';__34: __35: uri = Liferay.Util.addParams('<%= PortalUtil.getPortletNamespace("1_WAR_privatemessagingportlet") %>userIds=' + u, uri) || uri;__36: ______Stacktrace: [Sanitized]
org.apache.jasper.JasperException: Ha sucedido una excepción al procesar la página JSP /view.jsp en línea 33____30: function() {__31: '<portlet:renderURL var="redirectURL" windowState="<%= LiferayWindowState.NORMAL.toString() %>" />'__32: __33: var uri = '<liferay-portlet:renderURL portletName="1_WAR_privatemessagingportlet" windowState="<%= LiferayWindowState.POP_UP.toString() %>"><portlet:param name="mvcPath" value="/new_message.jsp" /><portlet:param name="redirect" value="<%= redirectURL %>" /></liferay-portlet:renderURL>';__34: __35: uri = Liferay.Util.addParams('<%= PortalUtil.getPortletNamespace("1_WAR_privatemessagingportlet") %>userIds=' + u, uri) || uri;__36: ______Stacktrace: [Sanitized]
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at com.liferay.portlet.PortletRequestDispatcherImpl.dispatch(PortletRequestDispatcherImpl.java:331)
at com.liferay.portlet.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:112)
at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:371)
at com.liferay.util.bridges.mvc.MVCPortlet.include(MVCPortlet.java:387)
at com.liferay.util.bridges.mvc.MVCPortlet.doView(MVCPortlet.java:144)
at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:213)
at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:323)
at javax.portlet.GenericPortlet.render(GenericPortlet.java:233)
at com.uxorit.birthday.portlet.BirthdayPortlet.render(BirthdayPortlet.java:59)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)
at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:55)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:100)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:64)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:112)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:604)
at com.liferay.portlet.InvokerPortletImpl.invokeRender(InvokerPortletImpl.java:677)
at com.liferay.portlet.InvokerPortletImpl.render(InvokerPortletImpl.java:379)
at org.apache.jsp.html.portal.render_005fportlet_jsp._jspService(render_005fportlet_jsp.java:1230)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at com.liferay.portal.servlet.DirectRequestDispatcher.include(DirectRequestDispatcher.java:57)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.doDispatch(ClassLoaderRequestDispatcherWrapper.java:78)
at com.liferay.portal.servlet.ClassLoaderRequestDispatcherWrapper.include(ClassLoaderRequestDispatcherWrapper.java:53)
at com.liferay.portlet.PortletContainerImpl._doRender(PortletContainerImpl.java:655)
at com.liferay.portlet.PortletContainerImpl.render(PortletContainerImpl.java:138)
at com.liferay.portlet.SecurityPortletContainerWrapper.render(SecurityPortletContainerWrapper.java:141)
at com.liferay.portlet.RestrictPortletContainerWrapper.render(RestrictPortletContainerWrapper.java:126)
at com.liferay.portal.kernel.portlet.PortletContainerUtil.render(PortletContainerUtil.java:156)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer._render(PortletRenderer.java:120)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer.access$4(PortletRenderer.java:107)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:174)
at com.liferay.portal.layoutconfiguration.util.PortletRenderer$PortletRendererCallable.doCall(PortletRenderer.java:1)
at com.liferay.portal.kernel.executor.CopyThreadLocalCallable.call(CopyThreadLocalCallable.java:69)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:682)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:593)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.servlet.ServletException: javax.servlet.jsp.JspException
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
at com.liferay.portal.kernel.servlet.PageContextWrapper.handlePageException(PageContextWrapper.java:161)
at org.apache.jsp.view_jsp._jspService(view_jsp.java:441)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
... 59 more
Caused by: javax.servlet.jsp.JspException
at com.liferay.taglib.util.ParamTag.doStartTag(ParamTag.java:33)
at org.apache.jsp.view_jsp._jspx_meth_portlet_005fparam_005f0(view_jsp.java:478)
at org.apache.jsp.view_jsp._jspService(view_jsp.java:249)
... 62 more

I am well aware that the javascript code should go elsewhere and that I shouldn't hardcode the portlet's name. For now I am just trying to get this to work. Any ideas on what I am doing wrong?