开发者

Can a List<> be cast to a DataModel

I'm trying to do the following:

public String createByMarcas() {
    items = (DataModel) ejbFacade.findByMarcas(current.getIdMarca().getId());
    updateCurrentItem();
    return "List";
}

public List<Modelos> findByMarcas(int idMarca){
    return em.createQuery("SELECT id, descripcion FROM Modelos WHERE id_marca ="+idMarca+"").getResultList();
}

But I keep getting this expection:

Caused by: javax.ejb.EJBException
 at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5070)
 at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:4968)
 at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4756)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1906)
 at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
 at com.sun.ejb.contain开发者_Go百科ers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
 at $Proxy347.findByMarcas(Unknown Source)
 at controladores.__EJB31_Generated__ModelosFacade__Intf____Bean__.findByMarcas(Unknown Source)

Can anyone give a hand please? Thank you very much


You are looking for the function setWrapperData() of the JSF DataModel.

Example:

DataModel dataModel;
List list;

list = em.createQuery("Select b from Book b").getResultList();
dataModel.setWrapperData(list);


I guess the most obvious answer to your question is no. You query retuns a java.util.List, which is unrelated to a JSF DataModel, assuming that that's what you're casting to. I know nothing about JSF, but it seems that there is a ListDataModel which can be used to wrap a List, so that might help in your case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜