I'm trying to use the Tree component, in the PrimeFaces library, but due to a large amount of data I have to load it lazily. I followed a tutorial to do it, (http://blog.disy.net/primefaces-lazy-tree/) but it takes 15 seconds to load (instead of 23 seconds). Am I missing something in this tutorial or in my code? I can't let this like that because 15 seconds is way too long for the users.
Code:
public interface TreePodeFindWithParent {
List<VArboParObjectifsParents> findActiviteWithParent(Integer parentId);
}
Method in the lazy loading class
public class PodeLazyTreeNode extends DefaultTreeNode
{
...
...
public PodeLazyTreeNode(VArboParObjectifsParents data, TreePodeService service)
{
super(vArboParObjectifsParents.class.getSimpleName(), data, null);
this.service = service;
}
...
private void ensureChildrenFetched()
{
if (!childrenFetched)
{
childrenFetched = true;
if ((VArboParObjectifsParents)getData() != null)
{
Integer parentId = ((VArboParObjectifsParents)getData()).getIdRoot();
List<PodeLazyTreeNode> childNodes = service.findActiviteWithParent(parentId).stream().map(item
-> new PodeLazyTreeNode(item, service)).collect(Collectors.toList());
super.getChildren().addAll(childNodes);
}
}
}
Method in the Service
public class TreePodeService implements Serializable, TreePodeWithParent
{
...
...
@Inject
private PodeArboParObjectifsParentsDao podeArboObjParentDao;
...
@Override
public List<VArboParObjectifsParents> findActiviteWithParent(Integer parentId) {
// TODO Auto-generated method stub
return podeArboObjParentDao.findByIdParent(parentId);
}
DAO (Requests are done with the Data Module of Apache DeltaSpike):
@Repository(forEntity=VArboParObjectifsParents.class)
public interface PodeArboParObjectifsParentsDao extends EntityRepository<VArboParObjectifsParents, Integer>
{
List<VArboParObjectifsParents> findByIdParent(Integer idParent);
List<VArboParObjetcifsParents> findByIdTypeActivite(Integer idType);
}
Call of the method in the View:
@PostConstruct
public void initView()
{
initArbo();
}
public void initArbo()
{
List<VArboParObjectifsParents> vArbos = treePodeService.getPodeArboObjParentDao().findByIdTypeActivite(1);
this.root = new PodeLazyTreeNode(null, treePodeService);
for (int i = 0; i < vArbos.size(); i++)
{
root.getChildren().add(new PodeLazyTreeNode(vArbos.get(i), treePodeService));
}
}
UI:
<p:tree value="#{testView.root}" var="_node" >
<p:treeNode type="VArboParObjectifsParents">
<h:outputText value="#{_node}"/>
</p:treeNode>
</p:tree>