Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Portal Integration

12.9.2. Basic Communication

LiferayIPC is an invisible user interface component that can be used to send messages between two or more Vaadin portlets. You add it to an application layout as you would any regular user interface component.

LiferayIPC liferayipc = new LiferayIPC(); layout.addComponent(liferayipc);

You should be careful not to remove the invisible component from the portlet later if you modify the layout of the portlet.

The component can be used both for sending and receiving messages, as described next.

Sending Events

You can send an event (a message) with the sendEvent() method, which takes an event ID and the message data as parameters. The event is broadcast to all listening portlets. The event ID is a string that can be used to identify the recipient of an event or the event type.

liferayipc.sendEvent("hello", "This is Data");

If you need to send more complex data, you need to format or serialize it to a string representation as described in Section 12.9.5, “Serializing and Encoding Data”.

Receiving Events

A portlet wishing to receive events (messages) from other portlets needs to register a listener in the component with addListener().The listener receives the messages in a LiferayIPCEvent object. Filtering events by the ID is built in into the listener handler, you give the listened event ID as the first parameter for the addListener(). The actual message data is held in the data property, which you can read with getData().

liferayipc.addListener("hello", new LiferayIPCEventListener() { public void eventReceived(LiferayIPCEvent event) {

// Do something with the message data String data = event.getData();

Notification.show("Received hello: " + data);

}

});

A listener added to a LiferayIPC can be removed with removeListener().

12.9.3. Considerations

Both security and efficiency should be considered with inter-portlet communications when using the Vaadin IPC for Liferay.

Browser Security

As the message data is passed through the client-side (browser), any code running in the browser has access to the data. You should be careful not to expose any security-critical data in clientside messaging. Also, malicious code running in the browser could alter or fake messages. Sanitization can help with the latter problem and encryption to solve the both issues. You can also share the sensitive data through session attributes or a database and use the client-side IPC only to notify that the data is available.

Basic Communication

337

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]