0

I'm attempting to communicate two views, the first view within portlet-A, and the second view within portlet-B (both portlets within same .war). To do so, I've decided to use the JSF 'f:viewParam' and 'f:param' features in order to inject a property (from portlet-A view) into the request object, so that the portlet-B view can retrieve it from the request object and pass such property value to a view scoped backing bean property.

Portlet-A view code:

<p:dataScroller value="#{searchManager.List}" var="ccp" >
    ...
    <p:link value="#{ccp.title}" onclick="myonClick(event)" >
         <f:param name="id" value="#{ccp.id}" />             
    </p:link>
    ...
</p:dataScroller>

JS code:

function myonClick(event) {
    event.preventDefault();
    window.open("viewer", "_blank");
}

Note that portlet-B view have to be displayed on a Liferay-based page, different to the one where the portlet-A view is displayed.

Portlet-B view code:

<f:metadata>
    <f:viewParam name="id" value="#{resultItemManager.id}" />       
</f:metadata>

<h:head />

<h:body>
    <p>Details:</p>
        <h:outputText value="#{resultItemManager.id}" />
</h:body>

When portlet-B gets displayed, the browser address field is set to 'http://host:8080/viewer' and the tag gets rendered as '0' (zero).

I don't know if the way i'm doing the targeted task is the right one or not. But if it is, i don't know why it isn't working. So I'd really appreciate any help/comments. Thanks in advance.

txapeldot
  • 71
  • 2
  • 10
  • It seems like you are trying to accomplish [inter-portlet communication (IPC)](https://web.liferay.com/web/meera.success/blog/-/blogs/liferay-inter-portlet-communication-ipc-). I'd recommend you look at the Liferay Faces example portlets. Check out the jsf-ipc-events [bookings](https://github.com/liferay/liferay-faces-bridge-impl/tree/4.x/demo/jsf-ipc-events-bookings-portlet) and [customers](https://github.com/liferay/liferay-faces-bridge-impl/tree/4.x/demo/jsf-ipc-events-customers-portlet) portlets... – stiemannkj1 Jul 22 '16 at 19:51
  • ...or the [jsf-ipc-pub-render-params-portlet](https://github.com/liferay/liferay-faces-bridge-impl/tree/4.x/demo/jsf-ipc-pub-render-params-portlet). – stiemannkj1 Jul 22 '16 at 19:51
  • Certainly, it's a task to be accomplished under a IPC perspective. And the links you've provided are suitable. However, I found a way to solve what i wanted to do without using IPC paradigm. The way of solving it is based on the use of 'getOriginalServletRequest()' method from 'com.liferay.portal.util.PortalUtil' Liferay class. – txapeldot Aug 02 '16 at 08:18

1 Answers1

0

Portlet-A view code:

<p:dataScroller value="#{searchManager.List}" var="ccp" >
...
    <p:link value="#{ccp.title}" onclick="myonClick(event, #{ccp.id})" />
...
</p:dataScroller>

JS code:

function myonClick(event, itemId) {
    event.preventDefault();
    window.open("viewer" + "?id=" + itemId, "_blank");
}

Portlet-B view code (Portlet-B view have to be displayed on a Liferay-based page, different to the one where the portlet-A view is displayed):

<h:body>
    <p>Details</p>
    <h:outputText value="#{itemManager.id}" />              
</h:body>

Portlet-B side managed bean:

@ManagedBean(name = "resultItemManager")
@ViewScoped
public class ItemManager implements Serializable {

  @ManagedProperty(value = "")
  public long id;

  ...

  @PostConstruct
  public void init() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext extContext = facesContext.getExternalContext();
    RenderRequest renderRequest = (RenderRequest) extContext.getRequest();
    HttpServletRequest httpRequest = PortalUtil.getOriginalServletRequest(
         PortalUtil.getHttpServletRequest(renderRequest));
    this.id = Long.parseLong(httpRequest.getParameter("id"));
  }
}

This way, there is no need to use ViewParams. El 'itemId' param is appended to the http request so that it is retrieved in the init() PostConstruct method on the Portlet-B side. Moreover, the view is displayed on a new different page.

txapeldot
  • 71
  • 2
  • 10