I am using JSF Mojarra 2.1.13, PrimeFaces 3.5 and Spring 3.2.3 for my application. For DI I am using Spring approach (not CDI). I am following the tutorial on PrimeFaces demos with the collector: http://www.primefaces.org/showcase/ui/collector.jsf
Everything is working fine, I can add my values to the list, get them, etc.. The problem is that for e.g. if I open two browsers and adding some values into the list, then in another browser I am adding a few values as well, and if I refresh browsers I am seeing the all the values which has been entered in both browsers. So if I enter two values in one browser two in the other, after refreshing them I am seeing four values in both browsers. I want my values to not be shared across different sessions.
My bean looks like this:
@Component
@ManagedBean
public class ClientBean extends BaseBean {
private Client client = new Client();
private List<Client> clients = new LinkedList<>();
public String reInit() {
client = new Client();
return null;
}
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public List<Client> getClients() {
return clients;
}
public void setClients(List<Client> clients) {
this.clients = clients;
}
}
I know that I am creating global variables:
private Client client = new Client();
private List<Client> clients = new LinkedList<>();
But this is showed in tutorial. So how can I handle this situation to make collector work so that those variables won't be shared across different sessions?
EDIT
I have tried to annotate my bean with: @RequestScoped
or @SessionScoped
- didn't work. The same problem remains.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…