在JSF中,组件可以使用EL空运算符呈现,也可以不呈现
rendered="#{not empty myBean.myList}"
据我所知,操作符的工作方式既是null- check,也是check检查列表是否为空。
我想对我自己的自定义类的一些对象进行空检查,我需要实现哪些接口或接口的哪些部分?空运算符与哪个接口兼容?
发布于 2013-01-08 02:51:59
使用BalusC提出的实现集合的建议,我现在可以在扩展javax.faces.model.ListDataModel
的dataModel
上使用not empty操作符隐藏primefaces p:dataTable
代码示例:
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;
public class EntityDataModel extends ListDataModel<Entity> implements
Collection<Entity>, SelectableDataModel<Entity>, Serializable {
public EntityDataModel(List<Entity> data) { super(data); }
@Override
public Entity getRowData(String rowKey) {
// In a real app, a more efficient way like a query by rowKey should be
// implemented to deal with huge data
List<Entity> entitys = (List<Entity>) getWrappedData();
for (Entity entity : entitys) {
if (Integer.toString(entity.getId()).equals(rowKey)) return entity;
}
return null;
}
@Override
public Object getRowKey(Entity entity) {
return entity.getId();
}
@Override
public boolean isEmpty() {
List<Entity> entity = (List<Entity>) getWrappedData();
return (entity == null) || entity.isEmpty();
}
// ... other not implemented methods of Collection...
}
https://stackoverflow.com/questions/14185031
复制相似问题