Edited/updated values in p:dataTable rowEdit are not available in listener method as they are being overwritten by existing data from database

后端 未结 1 1225
迷失自我
迷失自我 2021-01-20 18:35

I\'m editing data with row editor as below.


    &         


        
相关标签:
1条回答
  • 2021-01-20 18:44

    Your problem is caused by performing business logic in a getter method. Every iteration over the data table will invoke the getter method. So, while JSF is busy iterating over the data table in order to set the submitted values in the model, the getter calls returns a new list from DB again and again.

    You're not supposed to perform business logic in a getter method. As long as you're a starter, you'd better refrain from touching the getter (and setter) methods and perform the job elsewhere in an one time called method.

    You likely need a @PostConstruct (and a true service/DAO class) here:

    private List<User> users;
    
    @EJB
    private UserService userService;
    
    @PostConstruct 
    public void init() {
        users = userService.list(); // Call the DB here.
    }
    
    public List<User> getUsers() {
        return users; // Just return the already-prepared model. Do NOT do anything else here!
    }
    

    See also:

    • Why JSF calls getters multiple times
    0 讨论(0)
提交回复
热议问题