Fórum

Emailalble link to launch into portlet?

thumbnail
David H Nebinger, modificado 14 Anos atrás.

Emailalble link to launch into portlet?

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
So I've got an order review portlet. Normally the first page has a form where user enters order id. Upon submit, the order is retrieved and user gets view showing the order information.

The one part that's missing is the ability to send an email link, one w/ parameters, to be used to launch liferay and get user to a specific point...

I know I could set up a public page w/ a friendly URL that has the order review portlet placed on it for getting into the portal at the right place.

The question is how I can use a parameter to have the order review portlet skip the first form and drop right into the order information view.

I.e. how can I email a link such as http://portal.example.com/web/orders/home?order_id=123 that would get the portlet to respond correctly?
thumbnail
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
hi david,

When user enter the form, an id will be generated and with that id , associating a url (which displays the view of entered data) must be sent as a mail to the user, Is that correct ?

First , at the time of your submision, add the code to send mail

  InternetAddress from = new InternetAddress(fromAddress, fromName);
                InternetAddress to = new InternetAddress(toAddress, toName);
                MailMessage mailMessage = new MailMessage(from, to, subject, body, true);
                MailServiceUtil.sendEmail(mailMessage);

subject,body,fromAddress,toAddress,fromName,toName are string type.

http://portal.example.com/web/orders/home?order_id= ORDER ID


send this in body.

for reference see this Sending an alert through Mail

With Regards,
V.Auditya
thumbnail
David H Nebinger, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
That will work if the email is generated from within the portlet, but I'm not going to be within a portlet necessarilly.

In the order review example, if I have an off hour task that runs to check orders that may need attention, that process is the one generating the email so it would not have access to the theme display, the portal or layout urls, etc. mentioned in the referenced link.

That said, there may be enough in your response and the referenced link for me to build the necessary code. When I get a solution, I'll try to follow up here...
thumbnail
Auditya manikanta Vadrevu, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Master Postagens: 621 Data de Entrada: 06/05/08 Postagens Recentes
hi David H Nebinger ,

The link i have just shown how they used. No need to use the themedisplay etc..,

That will work if the email is generated from within the portlet, but I'm not going to be within a portlet necessarilly.


this is not specified earlier .. whatz ur requirement ?


With Regards,
V.Auditya
thumbnail
David H Nebinger, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
I guess a web app example will explain...

My web app, orders, has an index.jsp page with a form w/ one input field for an order id and a submit button. On submit, the order id is used to query the db and the user ends up on the view.jsp page that shows the order information.

Since I know my urls and parameters, I can send an email with a url that simulates the form submission, i.e. http://example.com/order.action?order_id=123, that allows the user to skip the index.jsp page and get right into the view.jsp page.

I can use a java app that runs off-hours to query for orders requiring review and send an email w/ these links in it, and the email recipient just has to click the link to view the order.

In the portlal world, though, I've now got a portlet placed on a page w/ a friendly url. When the user opens the portal using this friendly url, the portal shows the form w/ the input field for the order id and the submit button. On submit, the portlet will end up rendering a view showing the order information in the same way the web application would have.

The problem is that off-hours piece. Right now I'm stuck sending an email w/ the order ids listed, so the user has to manually start the portal, copy n paste the order id into the form and submit, which is a bad implementation from the users point of view.

So, if I could do something like the friendly url plus portlet parameters, i.e. http://portal.example.com/web/orders/home?order_id=123, the users would be able to do the same thing in the portal that the old web application could have done by skipping the initial form view and getting right into the order review.

Does that explain things a little better?
thumbnail
Victor Zorin, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 1228 Data de Entrada: 14/04/08 Postagens Recentes
If order ID is already passed as an http parameter, it is delivered to your portlet render() method.
You can detect it and display order details to the customer. It is just a matter of modifying your portlet render action(s).
If need to identify step, you can add another parameter like web/orders/home?order_id=123&step=preview
thumbnail
David H Nebinger, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
Sorry, but I don't think that's correct...

I set up a test using a MyFaces-based portlet that I have. In it I defined an instance of org.apache.myfaces.portlet.DefaultViewSelector and referenced it in my portlet.xml file.

In the instance, I put the following methods:


	public String selectViewId(final RenderRequest request, final RenderResponse response) throws PortletException {
		if (logger.isDebugEnabled()) {
			final HttpServletRequest req = PortalUtil.getHttpServletRequest(request);

			if (req == null) {
				logger.error("Unable to get the servlet request!");
			} else {
				logRequest(req);
			}
		}

		return null;
	}

	private void logRequest(final HttpServletRequest httpRequest) {

		// logging here
		logger.debug("Incoming request:");

		logger.debug("  Remote Host: " + httpRequest.getRemoteHost() + " (addr: " + httpRequest.getRemoteAddr() + ").");
		logger.debug("  Request: " + httpRequest.getRequestURL());

		logger.debug("  Query: " + httpRequest.getQueryString());

		Enumeration nameEnum = httpRequest.getAttributeNames();

		if ((nameEnum != null) && (nameEnum.hasMoreElements())) {
			String name;
			int idx = 0;
			Object obj;

			logger.debug("  Attributes:");

			while (nameEnum.hasMoreElements()) {
				idx++;
				name = (String) nameEnum.nextElement();

				obj = httpRequest.getAttribute(name);

				if (obj == null) {
					logger.debug("    " + idx + ". Attr [" + name + "] is null.");
				} else {
					logger.debug("    " + idx + ". Attr [" + name + "] is [" + obj.toString() + "].");
				}
			}
		}

		nameEnum = httpRequest.getParameterNames();
		if ((nameEnum != null) && (nameEnum.hasMoreElements())) {
			String name;
			int idx = 0;
			Object obj;

			logger.debug("  Parameters:");

			while (nameEnum.hasMoreElements()) {
				idx++;
				name = (String) nameEnum.nextElement();

				obj = httpRequest.getParameter(name);

				if (obj == null) {
					logger.debug("    " + idx + ". Parm [" + name + "] is null.");
				} else {
					logger.debug("    " + idx + ". Parm [" + name + "] is [" + obj.toString() + "].");
				}
			}
		}

		final Cookie[] cookies = httpRequest.getCookies();

		if ((cookies != null) && (cookies.length > 0)) {
			logger.debug("  Cookies:");

			for (int idx = 0; idx < cookies.length; idx++) {
				logger.debug("    " + (idx + 1) + ". Cookie [" + cookies[idx].getName() + "] is [" + cookies[idx].getValue() + "].");
			}
		}
	}


Now, even though I was using the URL http://localhost:8080/user/dnebinger/home?orderId=123, I found the following in my log file:


Incoming request:
  Remote Host: 127.0.0.1 (addr: 127.0.0.1).
  Request: http://localhost:8080/c/portal/layout
  Query: p_l_id=10910
  Attributes:
    1. Attr [isPortletModeChanged] is [false].
    2. Attr [org.apache.myfaces.component.html.util.ExtensionFilter.doFilterCalled.render] is [true].
    3. Attr [com.liferay.portal.kernel.servlet.PortletServletConfig] is [org.apache.catalina.core.StandardWrapperFacade@c1401d].
    4. Attr [__acegi_session_integration_filter_applied] is [true].
    5. Attr [com.liferay.portal.kernel.servlet.PortletServletResponse] is [com.liferay.portal.kernel.servlet.StringServletResponse@2201aa2].
    6. Attr [TBBGL_PORTLET_TITLE_CHANGER] is [com.tbbgl.portlet.filter.impl.PortletTitleChangingFilter$InternalPortletTitleChanger@2ee35f5].
    7. Attr [com.liferay.portal.kernel.servlet.PortletServletFilterChain] is [com.sun.portal.portletcontainer.appengine.filter.FilterChainImpl@2eeaac8].
    8. Attr [openSessionInViewPortletFilter.FILTERED.render] is [true].
    9. Attr [org.apache.myfaces.component.html.util.ExtensionFilter.doFilterCalled] is [true].
    10. Attr [com.liferay.portal.kernel.servlet.PortletServletRequest] is [com.liferay.portal.servlet.NamespaceServletRequest@2201a27].
    11. Attr [PORTLET_ID] is [512_WAR_tbbglportletratequote].
   Cookies:
     1. Cookie [GUEST_LANGUAGE_ID] is [en_US].
     2. Cookie [COOKIE_SUPPORT] is [true].
     3. Cookie [LOGIN] is [646e6562696e67657240746262676c2e636f6d].
     4. Cookie [SCREEN_NAME] is [6d6f2b50646d7a2f2b33507769456e786e624b6266773d3d].
     5. Cookie [COMPANY_ID] is [10112].
     6. Cookie [ID] is [68752b56487744796869413d].
     7. Cookie [PASSWORD] is [4b386850716e36424f6d6f3d].
     8. Cookie [REMEMBER_ME] is [true].
     9. Cookie [JSESSIONID] is [59C30DFB9649FB4FDCBA5660BDEB3B1C].


So it seems clear that the portal is consuming the "?orderId=123" parameter passed in...

I also checked the RenderRequest for parameters, attributes, etc., but it didn't have any orderId reference in it either...
thumbnail
David H Nebinger, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
Okay, from my previous post it looks like any cookies defined in the primary page will get sent to the portlet, so I did another test...

Using FF and the WebTools addon, I added a cookie, ORDER_ID w/ value 123 on the root level, then reloaded my portlet.

I then checked the logs and voila:


Incoming request:
  Remote Host: 127.0.0.1 (addr: 127.0.0.1).
  Request: http://localhost:8080/c/portal/layout
  Query: p_l_id=10910
  Attributes:
    1. Attr [isPortletModeChanged] is [false].
    2. Attr [org.apache.myfaces.component.html.util.ExtensionFilter.doFilterCalled.render] is [true].
    3. Attr [com.liferay.portal.kernel.servlet.PortletServletConfig] is [org.apache.catalina.core.StandardWrapperFacade@c1401d].
    4. Attr [__acegi_session_integration_filter_applied] is [true].
    5. Attr [com.liferay.portal.kernel.servlet.PortletServletResponse] is [com.liferay.portal.kernel.servlet.StringServletResponse@3be6d2c].
    6. Attr [TBBGL_PORTLET_TITLE_CHANGER] is [com.tbbgl.portlet.filter.impl.PortletTitleChangingFilter$InternalPortletTitleChanger@3d96e35].
    7. Attr [com.liferay.portal.kernel.servlet.PortletServletFilterChain] is [com.sun.portal.portletcontainer.appengine.filter.FilterChainImpl@3cca541].
    8. Attr [openSessionInViewPortletFilter.FILTERED.render] is [true].
    9. Attr [org.apache.myfaces.component.html.util.ExtensionFilter.doFilterCalled] is [true].
    10. Attr [com.liferay.portal.kernel.servlet.PortletServletRequest] is [com.liferay.portal.servlet.NamespaceServletRequest@3be6cb1].
    11. Attr [PORTLET_ID] is [512_WAR_tbbglportletratequote].
   Cookies:
     1. Cookie [GUEST_LANGUAGE_ID] is [en_US].
     2. Cookie [COOKIE_SUPPORT] is [true].
     3. Cookie [LOGIN] is [646e6562696e67657240746262676c2e636f6d].
     4. Cookie [SCREEN_NAME] is [6d6f2b50646d7a2f2b33507769456e786e624b6266773d3d].
     5. Cookie [COMPANY_ID] is [10112].
     6. Cookie [ID] is [68752b56487744796869413d].
     7. Cookie [PASSWORD] is [4b386850716e36424f6d6f3d].
     8. Cookie [REMEMBER_ME] is [true].
     9. Cookie [JSESSIONID] is [59C30DFB9649FB4FDCBA5660BDEB3B1C].
     10. Cookie [ORDER_ID] is [123].


So it looks like the answer is going to be along the following lines:

1. Create a simple servlet that will accept the URL and parameter such as http://portal.example.com/order-servlet?orderId=123&redir=/web/order/home. The servlet should set a cookie, ORDER_ID with the given value, then redirect to the portal using the value for the redir parameter.

2. Create a DefaultViewSelector implementation that checks the value of the cookie. If it is set, then use the order review page as the default view, otherwise just let it jump to the form. If it does redirect, it should probably alter the value of the cookie so it doesn't trigger the wrong thing in the future.

Certainly feels like a hack, but it will accomplish my basic goal.

If anyone has a better idea, I'm all ears! ;-)
thumbnail
Victor Zorin, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 1228 Data de Entrada: 14/04/08 Postagens Recentes
David, I am not using Faces development, struts only.
But still, I do not see the need to use separate servlet, because when parameters are attached to friendly urls they are delivered directly to the portlet. Do you have trouble reading orderId? Or the question is more about the processing logic?
I also do not see the need of engaging cookies.
thumbnail
David H Nebinger, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
I don't think it really matters what the portlet implementation is, I think it has more to do with the friendly URL handling.

From the dumps that I provided above, clearly the orderId parameter is not available either at the portlet request level or at the servlet's request level.

The incoming URL has the /c/portal/layout as part of the request, not the original friendly url. I think the friendly url servlet is, in the process of handling the friendly url translation, dropping the initial orderId request parameter.

By the time it gets to my portlet, the orderId parameter simply is not there at all.

Granted the servlet/cookie scenario is just plain ugly and should not be necessary, but it would seem to be the only way to get this to work that I've come up with...
thumbnail
Victor Zorin, modificado 14 Anos atrás.

RE: Emailalble link to launch into portlet?

Liferay Legend Postagens: 1228 Data de Entrada: 14/04/08 Postagens Recentes
Have you seen this link?
We also have a lot of cases when request parameters are passed as part of friendly url. Do not have any problems reading them,
unless friendly url is in private zone and user has to go through authentication phase.