Fórum

IPC event + CDI not working

Alfonso Mateos, modificado 9 Anos atrás.

IPC event + CDI not working

New Member Postagens: 24 Data de Entrada: 11/07/12 Postagens Recentes
I don't get my IPC event catched from my receiving portlet. The portlet that sends the ipc event is "epsilon-menu", the receiving portlet is epsilon-movements. I've got my code like this:

Inside my portlet.xml I declare event definition, event publishing from portlet epsilon-menu and event processing in epsilon-movements:
<portlet>
<portlet-name>epsilon-menu</portlet-name>
<portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>/views/menu.xhtml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>edit</portlet-mode>
</supports>
<supported-locale>es_ES</supported-locale>
<supported-locale>ca_ES</supported-locale>
<resource-bundle>portlets.epsilon-menu.Language</resource-bundle>
<portlet-info>
<title>Menu</title>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
<supported-publishing-event>
<qname xmlns:x="http://liferay.com/events">x:ipc.startWizardEvent</qname>
</supported-publishing-event>
</portlet>

<portlet>
<portlet-name>epsilon-movements</portlet-name>
<portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
<init-param>
<name>javax.portlet.faces.defaultViewId.view</name>
<value>/views/movements/processes.xhtml</value>
</init-param>
<init-param>
<name>javax.portlet.faces.bridgeEventHandler</name>
<value>es.gc.epsilon.core.liferay.event.StartWizardEvent</value>
</init-param>
<init-param>
<name>com.liferay.faces.bridge.preferPreDestroy</name>
<value>false</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>edit</portlet-mode>
</supports>
<supported-locale>es_ES</supported-locale>
<supported-locale>ca_ES</supported-locale>
<resource-bundle>portlets.epsilon-movements.Language</resource-bundle>
<portlet-info>
<title>Movimientos</title>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
<supported-processing-event>
<qname xmlns:x="http://liferay.com/events">x:ipc.startWizardEvent</qname>
</supported-processing-event>
</portlet>
.....

<filter>
<filter-name>CDIPortletFilter</filter-name>
<filter-class>com.liferay.cdi.portlet.bridge.CDIPortletFilter</filter-class>
<lifecycle>ACTION_PHASE</lifecycle>
<lifecycle>RENDER_PHASE</lifecycle>
<lifecycle>RESOURCE_PHASE</lifecycle>
<lifecycle>EVENT_PHASE</lifecycle>
</filter>

<filter-mapping>
<filter-name>CDIPortletFilter</filter-name>
<portlet-name>epsilon-admin-users</portlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>CDIPortletFilter</filter-name>
<portlet-name>epsilon-organisation</portlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>CDIPortletFilter</filter-name>
<portlet-name>epsilon-recruiting</portlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>CDIPortletFilter</filter-name>
<portlet-name>epsilon-menu</portlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>CDIPortletFilter</filter-name>
<portlet-name>epsilon-movements</portlet-name>
</filter-mapping>
.....
<event-definition>
<qname xmlns:x="http://liferay.com/events">x:ipc.startWizardEvent</qname>
<value-type>java.lang.String</value-type>
</event-definition>


Inside faces-config.xml I've got this navigation rule but it doesn't even consider it... or maybe it's just that the event is not fired or transmitted from one portlet to another....

<navigation-rule>
<from-view-id>/views/movements/processes.xhtml</from-view-id>
<navigation-case>
<from-outcome>ipc.startWizardEvent</from-outcome>
<to-view-id>/views/movements/massiveRecruitingStep1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

I debugged GenericFacesPortlet.init() and verified that javax.portlet.faces.bridgeEventHandler is correctly loaded and that my StartWizardEvent class is correctly set from that init method.

Then in my backing bean i've got (just the same way as in ipc-events demos in liferay-faces:

public void startProcess(ActionEvent actionEvent) {
try {
processVariables.setVariables(new HashMap<String, Object>());
processVariables.setStep(1);
processVariables.setRecruitingTitle(massiveRecruitingModelBean.getRecruitingTitle());

StartRequest request = new StartRequest(sessionTokens.getOAuthToken(),
sessionTokens.createAuthorizatedRequestInfo(),
locale.toString(),
processVariables.getVariablesMap());
String processInstanceId = massiveRecruitingServiceClient.start(request);

QName qName = new QName("http://liferay.com/events", "ipc.startWizardEvent");
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
ActionResponse actionResponse = (ActionResponse) externalContext.getResponse();
try {
externalContext.redirect("http://localhost:18080/group/guest/movements");
}
catch (Exception e) {
_log.error(e);
}
actionResponse.setEvent(qName, "step1");

} catch (Exception e) {
//TODO: handle this exception.
_log.error(e);
}
}

I debugged it and verified that setEvent is executed.

The xhtml that executes this code is:
<h:commandButton id="startButton2" value="probar este"
actionListener="#{massiveRecruitingBackingBean.startProcess}"></h:commandButton>

My StartWizardEvent class does nothing so far. But the problem is that is never reached, I debugged it ant id never stops there:

import javax.faces.context.FacesContext;
import javax.portlet.Event;
import javax.portlet.faces.BridgeEventHandler;
import javax.portlet.faces.event.EventNavigationResult;

public class StartWizardEvent implements BridgeEventHandler {
@Override
public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {

EventNavigationResult eventNavigationResult = null;
String eventQName = event.getQName().toString();

if (eventQName.equals("{http://liferay.com/events}ipc.startWizardEvent")) {
//TODO: handle startWizard event.
int i = 0;
}
return eventNavigationResult;
}
}

When I compare my code to the code from ipc-events-customers-portlet and ipc-events-bookings-portlet I don't see anything missing, the only thing I see is CDIPortletFilter, don't know if this could be the culprit...

I set a breakpoint in CDIPortletFilter in this method, but it doesn't stop here...
public void doFilter(
EventRequest eventRequest, EventResponse eventResponse,
FilterChain filterChain)

I found this entry but it seems that the problem (in case this is the problem) was fixed by Neil a couple of years ago:
https://www.liferay.com/es/community/forums/-/message_boards/message/27267640

I've got set the portal-ext.properties like this:
# IPC events
portlet.event.distribution=layout-set
layout.default.p_l_reset=false
tags.compiler.enabled=false

In fact the liferay-faces demo is working at the very same liferay instance (and the very same underlying jboss, of course) that epsilon-menu and epsilon-movements, so I assume that those settings inside portal-ext are correct and enough.

My versions are:
liferay-faces demos: 3.1.4-ga5

in my project I have:
<liferay.version>6.1.2</liferay.version>
<com.liferay.cdi.version>6.2.0.2</com.liferay.cdi.version>
<com.liferay.portal.version>6.1.2</com.liferay.portal.version>
<com.liferay.faces.version>3.1.4-ga5</com.liferay.faces.version>


<dependency>
<groupId>com.liferay.cdi</groupId>
<artifactId>cdi-portlet-bridge-shared</artifactId>
<version>${com.liferay.cdi.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-alloy</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>liferay-faces-portal</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>
<!-- Liferay Faces patches: https://www.liferay.com/es/web/neil.griffin/blog/-/blogs/announcement-patches-for-liferay-faces-ga5 -->
<dependency>
<groupId>com.liferay.faces.patches</groupId>
<artifactId>liferay-faces-1513-patch</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces.patches</groupId>
<artifactId>liferay-faces-2006-patch</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces.patches</groupId>
<artifactId>liferay-faces-2007-patch</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces.patches</groupId>
<artifactId>liferay-faces-2056-patch</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces.patches</groupId>
<artifactId>liferay-faces-2061-patch</artifactId>
<version>${com.liferay.faces.version}</version>
</dependency>

<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${com.liferay.portal.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>${com.liferay.portal.version}</version>
</dependency>
<!-- Java Server Faces -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${com.sun.faces.version}</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${com.sun.faces.version}</version>
</dependency>
<!-- Injections -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>${javax.enterprise.version}</version>
</dependency>
Alfonso Mateos, modificado 9 Anos atrás.

RE: IPC event + CDI not working

New Member Postagens: 24 Data de Entrada: 11/07/12 Postagens Recentes
Hi guys, solved half of the problem without touching a single line of code...
It happens that I placed the portlet that sends the event and the portlet that receives under different "areas" of my site, one of them was in http://localhost:18080/web/guest/home and the receiving one was in http://localhost:18080/user/admin/movements.

Once I set the first portlet under http://localhost:18080/user/admin/ I can hit my StartWizardEvent class with the debugger.

The unsolved part of the problem is that I cannot get my navigation rule working... I've got it like this: processes.xhtml is the defaultViewId from the portlet that is waiting for the event, and then I set the from-outcome as the event name, just the same way that it's set in the liferay-faces demo inside jsf2-ipc-events-bookings-portlet module:

<navigation-rule>
<from-view-id>/views/movements/processes.xhtml</from-view-id>
<navigation-case>
<from-outcome>ipc.startWizardEvent</from-outcome>
<to-view-id>/views/movements/massiveRecruitingStep1.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

Any hint on how to start with to find out why is not working?
Thanks in advance.
thumbnail
Vernon Singleton, modificado 9 Anos atrás.

RE: IPC event + CDI not working

Expert Postagens: 315 Data de Entrada: 14/01/13 Postagens Recentes
Hi Alfonso,

I recommend that you start with the working IPC events customers and booking portlets, and then add your CDI code.
There are several things you need to make sure of .... make sure that the model bean that you receive in your receiving portlet is session scoped, and of course make sure that you set your outcome in a javax.portlet.faces.event.EventNavigationResult the same way it is being done in the bookings portlet.

I did not see you creating a new EventNavigationResult in the code you posted above.

Nevertheless, it is probably better if you start with the working customer and bookings portlets and then add your CDI injection to that portlet to see if you can get that working.

Hope that helps,
Vernon
Alfonso Mateos, modificado 9 Anos atrás.

RE: IPC event + CDI not working

New Member Postagens: 24 Data de Entrada: 11/07/12 Postagens Recentes
Hi Vernon,

You were right about EventNavigationResult, so I created that new EventNavigationResult like this:

public class StartWizardEvent implements BridgeEventHandler {

private static final Logger logger = LoggerFactory.getLogger(StartWizardEvent.class);

@Override
public EventNavigationResult handleEvent(FacesContext facesContext, Event event) {
EventNavigationResult eventNavigationResult = null;
String eventQName = event.getQName().toString();

if (eventQName.equals("{http://liferay.com/events}ipc.startWizardEvent")) {
Serializable value = event.getValue();

// FACES-1465: If the payload is wrapped, then a redirect may have taken place. In any case, get the
// payload from the wrapper.
if (value instanceof EventPayloadWrapper) {
value = ((EventPayloadWrapper) value).getWrapped();
}
String fromAction = null;
String outcome = "ipc.customerSelected";
eventNavigationResult = new EventNavigationResult(fromAction, outcome);
logger.debug("Received event ipc.startWizardEvent");
}
return eventNavigationResult;
}
}

Now I can get the two portlets communicated when they are placed at the same page: when I click a commandButton in portlet1 then portlet2 switches to the view that I mention in navigation-rule with the outcome = ipc.StartWizardEvent.

But if I place portlet2 in a different page it says:

java.lang.IllegalStateException: Unable to load current conversations from the associated request, something went badly wrong when associate() was called
at org.jboss.weld.context.AbstractConversationContext.getCurrentConversation(AbstractConversationContext.java:363)
at org.jboss.weld.jsf.ConversationAwareViewHandler.getActionURL(ConversationAwareViewHandler.java:102)

I'm not trying to pass any data from portlet1 to portlet2, I'm just trying to force portlet 2 to show a view that is different than the one set in defaultViewId, so I think that I would not need that ModelBean, am I right?

I don't know if this lets you figure out what's my mistake... Or something that can give me a clue...
Alfonso Mateos, modificado 9 Anos atrás.

RE: IPC event + CDI not working

New Member Postagens: 24 Data de Entrada: 11/07/12 Postagens Recentes
Hi, Vernon, I got it!

If I create a default page at /group/guest/default and drop a portlet1 in there and then a page at /group/guest/movements and drop a portlet2 the IPC communication and the redirect work fine, and the navigation-rule is used correctly.

If I just go to "Go to" > <MySite> Private Pages and drop portlet1 in there then when skips to /group/guest/movements the portlet2 is still showing its default view (no navigation-rule is applied).

If I drop portlet1 at "Go to" > <My Site> Public Pages then I get that error about
java.lang.IllegalStateException: Unable to load current conversations from the associated request, something went badly wrong when associate() was called

Don't know still why.... Do you know why is this happening?
But its working because of your hint about new EventNavigationResult! ;-)
thumbnail
Vernon Singleton, modificado 9 Anos atrás.

RE: IPC event + CDI not working

Expert Postagens: 315 Data de Entrada: 14/01/13 Postagens Recentes
Hi Alfonso,

Regarding the IllegalStateException, I recommend that you take a look at this issue:
https://issues.liferay.com/browse/FACES-1719

So there you will see that we have a new liferay-faces-cdi-weld.jar dependency that you can build from source and see if that fixes the problem:
https://github.com/liferay/liferay-faces/tree/master/support/cdi/cdi-weld

Also, make sure you are following these basic instructions here:
https://www.liferay.com/community/wiki/-/wiki/Main/Developing+JSF+Portlets+with+CDI

I seem to remember that you are using Jboss, you may need to upgrade weld on Jboss as follows:
https://dev.liferay.com/discover/portal/-/knowledge_base/6-1/errata-for-using-liferay-portal-6-1#upgrading-weld-in-jboss-7

Hope that helps,
Vernon
Alfonso Mateos, modificado 9 Anos atrás.

RE: IPC event + CDI not working

New Member Postagens: 24 Data de Entrada: 11/07/12 Postagens Recentes
Hi Vernon,

About the issue FACES-1719 it seems to be for version 6.2 of liferay, am I right? I'm using liferay portal 6.1.2 with Jboss EAP 6.3... Is it quite probable that I should upgrade to 6.2 to get rid of this issue?

About the instructions for JSF+CDI and upgrading Mojarra we already did some months ago and we are using CDI with JSF flawlessly so far...

Thanks a lot for your attention, you are very kind :-)
thumbnail
Vernon Singleton, modificado 9 Anos atrás.

RE: IPC event + CDI not working

Expert Postagens: 315 Data de Entrada: 14/01/13 Postagens Recentes
Hi Alfonso,

Alfonso Mateos:
About the issue FACES-1719 it seems to be for version 6.2 of liferay, am I right? I'm using liferay portal 6.1.2 with Jboss EAP 6.3... Is it quite probable that I should upgrade to 6.2 to get rid of this issue?

You could upgrade to Liferay Portal 6.2, but that may be too much work. Never fear! Liferay has been working for you, and the fix for FACES-1719 should have been back ported for use with Liferay Faces Bridge 3.1, it just has not been released to maven central yet.

So you could just checkout the 3.1.x branch and build the jar for your version of the Liferay Portal.
https://github.com/liferay/liferay-faces/tree/3.1.x/support/cdi/cdi-weld

Hope that helps,
Vernon