PrimeFaces dataTable with variable columns and specific editable cells

前端 未结 1 1530
小鲜肉
小鲜肉 2021-01-20 13:38

I need to create a table where the headers list are brought from a model. The table contents are also stored in the model and p:dataTable loop on the data to show the conten

1条回答
  •  被撕碎了的回忆
    2021-01-20 14:13

    The input component's value must be bound to a writable value expression. What you've there is a direct getter method invocation and thus essentially read-only. This is indeed not going to work. You need to specify a property name of the #{entity}. You can use the brace notation to specify the property name as a variable like so #{entity[propertyName]}.

    So, basically:

    
        
            
                
                    #{entity[propertyName]}
                
                
                    
                
            
        
    
    

    As to the column header, rather refactor out that into a Map where the key is the propertyName and the value is the header.

            
                #{bean.columnHeaders[propertyName]}
            
    

    Or better yet, use a normal i18n resource bundle for that where the propertyName represents part of the bundle key.

            
                #{bundle['table.column.header.' += propertyName]}
            
    

    As to the editable check, rather wrap propertyName and editable in another bean (and perhaps also columnHeader if you don't want to use a i18n bundle), e.g. Field and then use like below:

        
            
                
                    #{entity[field.propertyName]}
                
                
                    
                
            
        
    

    All in all, it just boils down to preparing and providing the right model the view expects. This way the getData() thing isn't necessary.

    0 讨论(0)
提交回复
热议问题