PrimeFaces DataTable CellEdit get entity/object

前端 未结 3 2125
栀梦
栀梦 2021-02-14 04:40

I have a datatable which displays various entities based on a List<>. When I select a cell for editing I want to be able to also get the entity somehow in order to update it.

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-14 04:44

    One way would be to programmatically EL-evaluate the current .

    Given a

    
    

    you could get it as follows

    public void onCellEdit(CellEditEvent event) {
        FacesContext context = FacesContext.getCurrentInstance();
        Entity entity = context.getApplication().evaluateExpressionGet(context, "#{entity}", Entity.class);
        // ...
    }
    

    Another way, if you're not interested in the CellEditEvent argument, would be to override the CellEditEvent argument altogether by passing the currently iterated entity as argument instead:

    
    

    with

    public void onCellEdit(Entity entity) {
        // ...
    }
    

    Please note that you cannot keep the CellEditEvent and pass additional arguments. This answer would otherwise obviously have been given.

提交回复
热议问题