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

Integrating with the Server-Side

public class MyState extends ComponentState { private URLReference myIcon;

public URLReference getMyIcon() { return icon;

}

public void setMyIcon(URLReference myIcon) { this.myIcon = myIcon;

}

}

On the server-side, you can set the reference as a ResourceReference object, which creates the URL for the resource object given to the constructor as follows:

getState().setMyIcon(new ResourceReference(myResource));

It is normally meaningful only to set the resource on the server-side and then access it on the client-side. If you for some reason need to access it on the server-side, you need to cast the URLReference to the ResourceReference that exists on the server-side, and get the Resource object with getResource().

ResourceReference ref =

((ResourceReference) getState().getMyIcon()); if (ref != null) {

Resource resource = ref.getResource();

...

}

The URL for the resource can be accessed on the client-side with the getURL() method.

String url = getState().getMyIcon().getURL();

16.6. RPC Calls Between Clientand Server-Side

Vaadin supports making Remote Procedure Calls (RPC) between a server-side component and its client-side widget counterpart. RPC calls are normally used for communicating stateless events, such as button clicks or other user interaction, in contrast to changing the shared state. Either party can make an RPC call to the other side. When a client-side widget makes a call, a server request is made. Calls made from the server-side to the client-side are communicated in the response of the server request during which the call was made.

If you use Eclipse and enable the "Full-Fledged" widget in the New Vaadin Widget wizard, it automatically creates a component with an RPC stub.

16.6.1. RPC Calls to the Server-Side

RPC calls from the client-side to the server-side are made through an RPC interface that extends the ServerRpc interface. A server RPC interface simply defines any methods that can be called through the interface.

For example:

public interface MyComponentServerRpc extends ServerRpc { public void clicked(MouseEventDetails mouseDetails);

}

The above example defines a single clicks() RPC call, which takes a MouseEventDetails object as the parameter.

368

RPC Calls Between Clientand Server-Side

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