Iceface Liferay IPC
[Logo]
ICEsoft.org Forums: ICEfaces, ICEmobile, ICEpdf
[Search] Search   [Recent Topics] Recent Topics   [Groups] Home Page | www.icefaces.org  [Register] Register  [Login] Login 
Iceface Liferay IPC  XML
Forum Index -> Portals & Portlets
Author Message
szeminator

Joined: 06/05/2009 00:00:00
Messages: 21
Offline


Hi guys,

i have the following situation. I have two portlets, both implemented with icefaces and i can share attributes between them..thats not the problem...but i want to call a method or send an event from the one portlet to the other one...have you guys out there any suggestions/links/tutorials/examples?

regards
sze
deryk.sinotte


Joined: 26/10/2004 00:00:00
Messages: 936
Offline


ICEfaces doesn't support inter-portlet communication (IPC) directly. For that you need a Portlet 2.0 compliant container. A quick Google showed some example code from Sun that discusses this feature:
http://docs.sun.com/app/docs/doc/819-5070/gcykz?a=view

Deryk Sinotte
Team Lead
ICEsoft Technologies, Inc.
szeminator

Joined: 06/05/2009 00:00:00
Messages: 21
Offline


ok i already had such links to IPC without any connection to icefaces...but how do you manage that 2 portlets both developed with icefaces communicate with each other...i tried the way of the location portlet in the sample files..but that has some weired effects...

Is there no common way how you communicate portlet2portlet?

or is it able to map such a example that you mentioned to the iceface portlets?

regards
deryk.sinotte


Joined: 26/10/2004 00:00:00
Messages: 936
Offline


IPC is the specificied "official" way to communicate between 2 portlets but we don't currently have an example that shows this.

The method used in the Location portlets uses Ajax Push, which really isn't quite the same thing. It uses the SessionRenderer API and some shared data. When the data in one portlet changes, the SessionRenderer refreshes the portlets, causing them to update in the browser. So it's not actually a way to call a method or communicate with another portlet directly.

Deryk Sinotte
Team Lead
ICEsoft Technologies, Inc.
szeminator

Joined: 06/05/2009 00:00:00
Messages: 21
Offline


So my attempt to solve my problem..it is similar to the location portlet..but it doesn't work...it has weired side effects..maybe if you have liferay on your computer you can try it out..just deploy the attaced .war

My code is:

FirstPortlet.java
Code:
 public class FirstPortlet {
 
     private EventCoordinator ec;
     
 	public void call2ndPortlet(){
 		ec.setName("Hello 2nd Portlet");
 	}
 	
 	public String getName(){
 		String name = ec.getName();
 		if(name != null)
 			return name;
 		return "got no name";
 	}
 
 	/**
 	 * @return the ec
 	 */
 	public EventCoordinator getEc() {
 		return ec;
 	}
 
 	/**
 	 * @param ec the ec to set
 	 */
 	public void setEc(EventCoordinator ec) {
 		this.ec = ec;
 	}
 }
 


SecondPortlet.java
Code:
 public class SecondPortlet {
 
     private EventCoordinator ec;
     
 	public void call1stPortlet(){
 		ec.setName("Hello 1st Portlet here i am!");
 	}
 	
 	public String getName(){
 		String name = ec.getName();
 		if(name != null)
 			return name;
 		return "got no name";
 	}
 	
 	public boolean isRender(){
 		return false;
 	}
 
 	/**
 	 * @return the ec
 	 */
 	public EventCoordinator getEc() {
 		return ec;
 	}
 
 	/**
 	 * @param ec the ec to set
 	 */
 	public void setEc(EventCoordinator ec) {
 		this.ec = ec;
 	}
 }
 


EventControler.java
Code:
 public class EventCoordinator {
 	
 	private String groupName;
 	
 	public void setSharedparameter(String name, Object value){
         if (groupName == null) {
             groupName = getSessionID();
             SessionRenderer.addCurrentSession(groupName);
         }
         setApplicationAttribute(name,value);
         SessionRenderer.render(groupName);
 	}
 	
 	public Object getSharedparameter(String name){
 		return getApplicationAttribute(name);
 	}
 	
 	public String getName(){
 		System.out.println("In " + this.getClass().getName() + " getName");
 		return (String)getSharedparameter("name");
 	}
 	
 	public void setName(String nameval){
 		System.out.println("In " + this.getClass().getName() + " setName with value " + nameval);
         setSharedparameter("name",nameval);
 	
 	}
 	
     private String getSessionID() {
         return getPortletSession().getId();
     }
 
     private PortletSession getPortletSession() {
         FacesContext fc = FacesContext.getCurrentInstance();
         ExternalContext ec = fc.getExternalContext();
         Object sessObj = ec.getSession(false);
         if (sessObj != null && sessObj instanceof PortletSession) {
             return (PortletSession) sessObj;
         }
         return null;
     }
     
     private Object getApplicationAttribute(String name) {
         return getPortletSession().getAttribute(name, PortletSession.APPLICATION_SCOPE);
     }
 
     private void setApplicationAttribute(String name, Object val) {
         getPortletSession().setAttribute(name, val, PortletSession.APPLICATION_SCOPE);
     }
 
 }
 


firstportlet.jspx
Code:
  <ice:form>
     <ice:panelGroup>
         <ice:outputText value="Firstportlet ssseerrvaasss"/>
     </ice:panelGroup>
     <ice:panelGroup>
     	        <ice:outputText value="FIRSTPORTLET: #{firstportlet.name} "/>
                  <ice:commandButton id="call2ndPortlet"
                            value="call2ndPortlet"
                            action="#{firstportlet.call2ndPortlet}"/>
                            <br/>
     </ice:panelGroup>
     </ice:form>
 


secondportlet.jspx
Code:
  <ice:form>
     <ice:panelGroup>
         <ice:outputText value="SecondPortlet i bins"/>
     </ice:panelGroup>
     <ice:panelGroup>
     	        <ice:outputText value="SECONDPORTLETTTTT: #{secondportlet.name} "/>
                  <ice:commandButton id="call1stPortlet"
                            value="call1stPortlet"
                            action="#{secondportlet.call1stPortlet}"/>
                            <br/>
     </ice:panelGroup>
     </ice:form>
 


faces-config.xml
Code:
     <managed-bean>
         <managed-bean-name>eventcoordinator</managed-bean-name>
         <managed-bean-class>
             com.util.EventCoordinator
         </managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
     </managed-bean>
     <managed-bean>
         <managed-bean-name>secondportlet</managed-bean-name>
         <managed-bean-class>
     		com.model.SecondPortlet
         </managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
         <managed-property>
             <property-name>ec</property-name>
             <value>#{eventcoordinator}</value>
         </managed-property>
     </managed-bean>
     <managed-bean>
         <managed-bean-name>firstportlet</managed-bean-name>
         <managed-bean-class>
     		com.model.FirstPortlet
         </managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
         <managed-property>
             <property-name>ec</property-name>
             <value>#{eventcoordinator}</value>
         </managed-property>
     </managed-bean>
 


The idea...store the name in the shared Properties and then press the button and render the portlets again..so the portlets read the new value in the property and display this value...so far so good..but if i press the button in the first portlet..somehow the CONTENT not the value of the property is shown in the first portlet...i don't know how this is possible....

regards
 Filename IPC_Icefaces.war [Disk] Download
 Description
 Filesize 4974 Kbytes
 Downloaded:  94 time(s)

loic.salou


Joined: 03/10/2008 00:00:00
Messages: 83
Offline


I quickly read your posts and if I understand well you share you data using the portlet session. I faced an issue using the portlet session to share data. Since I've been using the http session itself it works fine.

My application is based on icefaces, in liferay. I've got several portlets, several faces, and I share data between portlets and pages "icefaces way".
JSF pages must be registered in the same group using:

OnDemandRenderer odr = renderManager.getOnDemandRenderer("group1");
odr.add(this);

When I want to "send" data from a page to another (whatever the portlet it belongs to), I just store the data in the session using:

FacesContext facesContext = FacesContext.getCurrentInstance();
PortletSession portletSession =(PortletSession) facesContext.getExternalContext().getSession(false);
portletSession.setAttribute(key, data,PortletSession.APPLICATION_SCOPE);


then I trigger an ajax refresh using:

OnDemandRenderer onDemandRenderer =getRenderManager().getOnDemandRenderer("group1");
onDemandRenderer.requestRender();


so that all jsf pages come and read their data. the second page can just pick this data from the session and you're done.
BatouChou

Joined: 11/01/2010 00:00:00
Messages: 2
Offline


I am devlopping a lifray + IceFaces app which uses the IPC with the Ajax push method, and I don't realy understand how the "groups" system, specified in the "getOnDemandRenderer" methods, works.

It renders all the views depending on the bean that has a render manager with this group?

It renders all the chanched views?

According to the IceFaces documentation, the render groups are made for re-rendering components between all clients (the chat room example) but I have experienced something different: the re-rendering is actually working only on the view of the client that have triggered the change. It's fine for me because I don't need to re-render all clients on my actions but it's quite confusing for me.

Can someone just explain me how the render groups work in a portlet (with IPC) context.
 
Forum Index -> Portals & Portlets
Go to:   
Powered by JForum 2.1.7ice © JForum Team