掲示板
How to implement IPC(Inter Portlet Communication) of 2 GWT portlets
12年前 に Jianjun Chen によって更新されました。
How to implement IPC(Inter Portlet Communication) of 2 GWT portlets
New Member 投稿: 2 参加年月日: 09/08/01 最新の投稿
I implement IPC of 2 GWT portlets. I consider GWT with Liferay is more powerful.
The IPC explains see there(http://www.liferay.com/zh/community/wiki/-/wiki/Main/portlet+to+portlet+communication), I reference [2.3 Client-Side IPC] in this article. I write GWT portlet since 2007 from Liferay 4.2.3 to 5.1.2 and 5.2.3. Now is based on Liferay 6.0.6.
There are 2 GWT portlets, one is ipcA-portlet, It will trigger event when some button clicked.
Another portlet is ipcB-portlet, it will create a listener when initialize,
Deploy and put the 2 portlets to a same portal page, then click a button in ipcA-portlet, then it will trigger change event in ipcB-portlet.
Please reference attached war files.
The IPC explains see there(http://www.liferay.com/zh/community/wiki/-/wiki/Main/portlet+to+portlet+communication), I reference [2.3 Client-Side IPC] in this article. I write GWT portlet since 2007 from Liferay 4.2.3 to 5.1.2 and 5.2.3. Now is based on Liferay 6.0.6.
There are 2 GWT portlets, one is ipcA-portlet, It will trigger event when some button clicked.
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
getService().sayHello(name.getText(), new AsyncCallback(){
public void onFailure(Throwable thrwbl) {
Window.alert(thrwbl.getMessage());
}
public void onSuccess(Object t) {
//label.setText(t.toString());
fire(t.toString());
}
});
}
});
public static native void fire(String msg) /*-{
$wnd.Liferay.fire('sayhello', {
name : msg,
});
}-*/;
Another portlet is ipcB-portlet, it will create a listener when initialize,
public void onModuleLoad() {
Panel rootpanel = RootPanel.get("layout-ipcB");
MainPanel mainpanel = new MainPanel();
mainpanel.setWidth("100%");
rootpanel.add(mainpanel);
listen(mainpanel);
}
public static native void listen(MainPanel mainpanel) /*-{
$wnd.Liferay.on('sayhello', function(event) {
$wnd.alert('I Say '+ event.name);
// See http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html
mainpanel.@com.example.client.MainPanel::change(Ljava/lang/String;)(event.name);
});
}-*/;
Deploy and put the 2 portlets to a same portal page, then click a button in ipcA-portlet, then it will trigger change event in ipcB-portlet.
Please reference attached war files.