目前,为了清除并重新加载会话,我必须重新启动Web服务器。
有两种方法:
Put them in the view scope instead. Storing view-specific data sessionwide is a waste. If you have a performance concern, you should concentrate on implementing connection pooling, DB-level pagination and/or caching in the persistence layer (JPA2 for example supports second level caching).
@ManagedBean
@ViewScoped
public class FooBean {
// ...
}
Add a public load()
method so that it can be invoked from the action method (if necessary, from another bean).
@ManagedBean
@SessionScoped
public class FooBean {
private List<Foo> foos;
@EJB
private FooService fooService;
@PostConstruct
public void load() {
foos = fooService.list();
}
// ...
}
which can be invoked in action method inside the same bean (if you submit the form to the very same managed bean of course):
public void submit() {
fooService.save(foos);
load();
}
or from an action method in another bean (for the case that your managed bean design is a bit off from usual):
@ManagedProperty("#{fooBean}")
private FooBean fooBean;
public void submit() {
fooService.save(foos);
fooBean.load();
}
This of course only affects the current session. If you'd like to affect other sessions as well, you should really consider putting them in the view scope instead, as suggested in the 1st way.