Stanowe komponenty sesyjne

Stanowy komponent sesyjny reprezentuje stan konwersacji z określonym klientem. Stan jest zapisywany w polach instancji tego komponentu sesyjnego, w powiązanych obiektach przechwytujących i w polach tych obiektów oraz w obiektach (i ich polach) osiągalnych dla tego komponentu za pośrednictwem referencji Javy.

Prosty stanowy komponent sesyjny można zdefiniować za pomocą adnotacji @Stateful:

package org.sample;

@Stateful
public class Cart {
    List<String> items;

    public ShoppingCart() {
        items = new ArrayList<Item>();
    }

    public void addItem(String item) {
        items.add(item);
    }

    public void removeItem(String item) {
        items.remove(item);
    }

    public void purchase() {
        // ...
    }

    @Remove
    public void remove() {
        items = null;
    }
}

Jak widać, ...

Get Java EE 6. Leksykon kieszonkowy now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.