例如实体:
@Entity
public class EntityObject
{
private String _value0 = "value0";
private String _value1 = "value1";
public String getValue0() {return _value0;}
public void setValue0(String value0) {_value0 = value0;}
public String getValue1() {return _value1;}
public void setValue1(String value1) {_value1 = value1;}
}
<p:datatable var="entity" value="#{bean.entities}">
<p:column headername="Column0">
<p:inputtext value="#{entity.value0}">
</p:column>
<p:column headername="Column1">
<p:inputtext value="#{entity.value1}">
</p:column>
</p:datatable>
托管bean是这样的非常基本的
@Named("bean")
public class TheBean
{
private List<EntityObject> _entities = new LinkedList<>();
public List<EntityObject> getEntities() {return _entities;}
public void setEntities(List<EntityObject> entities) {_entities = entities;}
@PostConstruct public void init()
{
_entities = Mock.generateEntities(5); //Imagine it could be a mock.
}
}
<p:datatable var="entity" value="#{bean.entities}">
<p:columns var="field" value="#{entity.fields}">
<p:inputText value="#{field}">
</p:columns>
</p:datatable>
当我们更改输入文本的值时,它实际上应该直接编辑实体对象的字段,就像我们直接手动将字段名称直接输入到输入文本中一样。
实现我试图做到的最好方法是什么。我真的想最小化Java代码,因为我知道它可以通过Bean中的代码完全生成,但是事后很难维护代码了吗?