I need to update an entity in my managed bean. I want to do this by passing this entity to a method in my managed bean with a MethodExpression
, with action
or actionListener
, which seems like the easier and clearest way. I want the managed bean to have view scope because I'm using Primefaces' dataTable
and it doesn't seem to call the action method when I change it to request scope (just my preRenderView
listener).
<h:commandXXXX action="#{bean.method(entity)}">
@ManagedBean(name="bean")
@ViewScoped
class Bean {
public void method(Entity entity) {
// ...
}
}
The problem is, this entity might have been changed by another user or just the same user in another page. I could retrieve the entity from the database again and overwrite the argument, but this feels silly and ugly.
public void method(Entity entity) {
entity = entityDAO.findById(entity.getId());
}
Is there a better way to do this? Would I have the newest state of the entity if I were to change the bean to request scope (assuming that I am able to make it work with the dataTable
)?