Forums de discussion

com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portlet.Ac

thumbnail
hamza jemai, modifié il y a 10 années.

com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portlet.Ac

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
Hi,
I'am using Liferay 6.1.1 and Primefaces 3.5 with Inter Portlet Communication and i have this error.
This is my code


public void onRowSelect(SelectEvent event) {
Projects project = (Projects) event.getObject();
QName qName = new QName("http://liferay.com/events", "ipc.projectSelected");
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
ActionResponse actionResponse = (ActionResponse) externalContext.getResponse();
Serializable eventPayload = project;
eventPayload = new EventPayloadWrapper(project, true);
actionResponse.setEvent(qName, eventPayload);
}
an in My View.xhhtm i have a dataTable :

<p:ajax event="rowSelect" listener="#{MyBean.onRowSelect}" />
thumbnail
Kyle Joseph Stiemann, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Hi Hamza,
The problem that you are experiencing is due to the fact that ajax cannot be used with IPC. If you want row selection to update the view of another portlet, you can put a <p:commandButton ajax="false" ... /> in one of the columns like the simple row selection in the primefaces showcase. When someone clicks the button, a full page post will be executed and the portlets will be updated.

Or you can try PrimePush which will allow you to use ajax with IPC. Check out this other forum post for more information on PrimePush.

- Kyle
thumbnail
hamza jemai, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
hanks Kyle for your replay,

have you any idea how to introduce this code in my exemple

@javax.portlet.ProcessEvent(qname = "{http://localhost:8080/web/guest/export}empinfo")
public void handleProcessempinfoEvent(javax.portlet.EventRequest request, javax.portlet.EventResponse response)
throws javax.portlet.PortletException, java.io.IOException {

javax.portlet.Event event = request.getEvent();
String value = (String) event.getValue();

System.out.print("value in process event>>>>>>>>>" + value);
response.setRenderParameter("empInfo", value);
}
thumbnail
Kyle Joseph Stiemann, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Might you be following the steps listed in the "Portlet to Portlet Communication" wiki article? The "Portlet to Portlet Communication" wiki is actually for non-JSF portlets, so it would be better for you to use something like Events or Public Render Parameters. If you want to allow two separate .wars to communicate, use Events, and take a look at our Customers and Bookings Events demo portlets. Otherwise, you can use Public Render Parameters, which are showcased in the JSF2 IPC Public Render Parameters demo.

- Kyle
thumbnail
hamza jemai, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
Hi kyle, thanks again for your reply,
Can the GenericPortlet communicate with the MVC portlet for exemple if i have the Customers in JSF (mvc Portet) and the Bookings in JSP page (GenerciPortlet)?
I'am using the demo (Customers & Bookings) of the show case and it running for mee but when i do it with JSP it's not, she execute only the @PreDestroy and ignore the methode with @PostConstruct annotation. I attach my Customers Portlet if you want to see.
Thanks a lot
thumbnail
Kyle Joseph Stiemann, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Hi Hazma,
I just want to make sure I understand your use case, you are using a JSF portlet as the customer which will communicate with the non-JSF GenericPortlet as the bookings, correct?

- Kyle
thumbnail
hamza jemai, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
yes Correct
thumbnail
Kyle Joseph Stiemann, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Okay, that should be fine. And @PostConstruct works for the non-JSF portlet, and @PreDestroy does not, correct? That seems strange because @PreDestroy and @PostConstruct should only work for JSF portlets. Non-JSF portlets will ignore those annotations, as far as I know.

However, even without the annotations, Events and IPC should still work.

-Kyle
thumbnail
hamza jemai, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
SO have you any idea how to do IPC with different Portlets (JSF and No JSf) ?
thumbnail
Kyle Joseph Stiemann, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Hi Hazma,
For the JSF portlet, you should be able to send and receive events in the way that we showcased in our demo. For the non-JSF portlet, you should follow the wiki and use the method you were using before. Neither of these approaches require @PostConstruct or @PreDestroy though, so could you give me some more information on why you need to use those annotations?

Thanks,
- Kyle
thumbnail
hamza jemai, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
Hi Kyle,
For me i just want to send an ID from JSF portlet to an MVC portlet (non-JSF), and if possible i want that the two portlet will be in separate Page
Thanks
thumbnail
Kyle Joseph Stiemann, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Liferay Master Publications: 760 Date d'inscription: 14/01/13 Publications récentes
Hi Hazma,
Here is a small demo portlet which takes events from the JSF customer portlet. To do this, you need to create a NonFacesPortlet in the bookings portlet demo with this code:


package com.liferay.faces.demos.portlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;

import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.ProcessEvent;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import com.liferay.faces.bridge.event.EventPayloadWrapper;
import com.liferay.faces.demos.dto.Customer;

public class NonFacesPortlet extends GenericPortlet {
	
	public NonFacesPortlet() {
		System.err.println("!@#$ nfs created.");
	}

	@Override
	@ProcessEvent(qname="{http://liferay.com/events}ipc.customerSelected")
	public void processEvent(EventRequest eventRequest, EventResponse eventResponse)
			throws PortletException, IOException {
		
		Serializable value = eventRequest.getEvent().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();
		}
		
		Customer customer = (Customer) value;
		System.err.println("!@#$ customer.getName() = " + customer.getFirstName() + " " + customer.getLastName());
		System.err.println(Long.toString(customer.getCustomerId()));
		
		eventRequest.getPortletSession().setAttribute("customerId", Long.toString(customer.getCustomerId()));
	}

	@Override
	protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		
		String customerId = (String) request.getPortletSession().getAttribute("customerId");
		PrintWriter writer = response.getWriter();
		writer.write("customerId = " + customerId);
		
	}
}


Then add this to the bookings portlet.xml file:


<portlet>
	<portlet-name>nfp</portlet-name>
	<display-name>NonFacesPortlet</display-name>
	<portlet-class>com.liferay.faces.demos.portlet.NonFacesPortlet</portlet-class>
	<supports>
		<mime-type>text/html</mime-type>
		<portlet-mode>view</portlet-mode>
	</supports>
	<portlet-info>
		<title>nfp</title>
		<short-title>nfp</short-title>
		<keywords>nfp</keywords>
	</portlet-info>
	<supported-processing-event>
		<qname xmlns:x="http://liferay.com/events">x:ipc.customerSelected</qname>
	</supported-processing-event>
</portlet>


Then add this to the bookings liferay-portlet.xml file:


<portlet>
	<portlet-name>nfp</portlet-name>
	<ajaxable>false</ajaxable>
</portlet>


Add <portlet id="nfp" /> to liferay-display.xml under the category tag.

To allow the portal to pass events between pages, you need to add these lines to your portal-ext.properties:

portlet.event.distribution=layout-set
layout.default.p_l_reset=false
tags.compiler.enabled=false


Then start up your server, and add the nfp portlet to a new page. Add the customers portlet to a different page and check the Send Redirect (Liferay Only) box and select the page which nfp is on from the dropdown. Now click on a customer and you should be sent to a new page which will tell you the ID of the customer that you clicked on.

Let me know if you need any more info.
- Kyle
thumbnail
hamza jemai, modifié il y a 10 années.

RE: com.liferay.portlet.ResourceResponseImpl cannot be cast to javax.portle

Junior Member Publications: 40 Date d'inscription: 04/12/12 Publications récentes
Hi Kyle,

Sorry for the delay in responding, yes it's the minimal solution and it's work for mee, now i cant communicate all portlet in my portal.

Thanks a lot

Jemai Hamza