0

Problem databinding

asked 2010-12-24 04:27:03 +0800

markdamne gravatar image markdamne
33

My code:
Articolo.zul



<?xml version="1.0" encoding="UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
...
<window id="winArticolo" use="controller.ControllerArticolo" border="none" width="1000px" height="230px" >
<grid id="demoGrid" style="border:none;" width="1200" mold="paging" pageSize="6" >
<!-- <columns> fixedLayout="true" height="200px"
<column hflex="4">Cliente</column>
<column hflex="5">Comune Sede Legale</column>
<column hflex="2">Provincia</column>
<column hflex="3">Partita IVA</column>
</columns> mold="paging" pageSize="10" mold="paging" pageSize="6"-->
<rows>
<row>
<listbox Width="1060px" id="lb1" model="@{winArticolo.articoli}" mold="paging" pageSize="7" vflex="false" selectedItem="@{winArticolo.selected}" onSelect="OpenSouthPanel(lb1.getSelectedIndex())">
<listhead sizable="true">
<!-- <listitem self="@{each='curr'}" sclass="cells" value="@{curr}"> checkmark="true"-->
<listheader label="Scegli" width="5%" />
<listheader label="Codice" width="10%" />
<listheader label="Nome" width="10%" />
<listheader label="Descrizione" width="10%" />
<listheader label="Tipo" width="10%" />
<listheader label="IVA %" width="10%" />
<listheader label="Prezzo €" width="10%" />
</listhead>
<listitem self="@{each='articoli'}" value="@{articoli}">

<!-- <listcell label=""/>
<a:bind value = “seller.firstName”/>
<textbox/>-->
<listcell><checkbox label="" /></listcell>

<listcell label= "@{articoli.codice}"/>
<listcell label= "@{articoli.nome}"/>
<listcell label= "@{articoli.descrizione}"/>
<listcell label= "@{articoli.tipo}"/>
<listcell label= "@{articoli.iva}"/>
<listcell label= "@{articoli.prezzo}"/>
<!-- <listcell label="@{customers.ragione}" /> #{} -->
</listitem>
</listbox>
</row>
</rows>
</grid>
</window>

ControllerArticolo.java

public class ControllerArticolo extends Window
{

List articoli = new ArrayList();
Articolo selected = new Articolo();

public ControllerArticolo() throws InterruptedException
{
EntityManagerFactory emf;
emf = Persistence.createEntityManagerFactory("jpaTest");

EntityManager em = emf.createEntityManager();
javax.persistence.Query q = em.createQuery("SELECT a FROM Articolo a");
articoli = q.getResultList();
em.close();
}

public List getArticoli() {
return articoli;
}


public Articolo getSelected() {
return selected;
}

public void setSelected(Articolo selected) {
this.selected = selected;
}
}

exception

java.lang.ClassCastException: class entity.Articolo cannot be converted to class org.zkoss.zul.Listitem.
org.zkoss.lang.Classes.coerce(Classes.java:1301)
org.zkoss.lang.reflect.Fields.set(Fields.java:151)
org.zkoss.zkplus.databind.Binding.myLoadAttribute(Binding.java:387)
org.zkoss.zkplus.databind.Binding.loadAttribute(Binding.java:336)
org.zkoss.zkplus.databind.DataBinder.loadAttrs(DataBinder.java:591)
org.zkoss.zkplus.databind.DataBinder.loadComponent0(DataBinder.java:546)
org.zkoss.zkplus.databind.DataBinder.loadAll(DataBinder.java:575)
org.zkoss.zkplus.databind.AnnotateDataBinderInit.doAfterCompose(AnnotateDataBinderInit.java:175)
org.zkoss.zk.ui.impl.RealInits.doAfterCompose(Initiators.java:82)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:376)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:291)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:243)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:164)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NoSuchMethodException: No contructor compatible with [entity.Articolo] in org.zkoss.zul.Listitem
org.zkoss.lang.Classes.newInstance(Classes.java:120)
org.zkoss.lang.Classes.coerce(Classes.java:1299)
org.zkoss.lang.reflect.Fields.set(Fields.java:151)
org.zkoss.zkplus.databind.Binding.myLoadAttribute(Binding.java:387)
org.zkoss.zkplus.databind.Binding.loadAttribute(Binding.java:336)
org.zkoss.zkplus.databind.DataBinder.loadAttrs(DataBinder.java:591)
org.zkoss.zkplus.databind.DataBinder.loadComponent0(DataBinder.java:546)
org.zkoss.zkplus.databind.DataBinder.loadAll(DataBinder.java:575)
org.zkoss.zkplus.databind.AnnotateDataBinderInit.doAfterCompose(AnnotateDataBinderInit.java:175)
org.zkoss.zk.ui.impl.RealInits.doAfterCompose(Initiators.java:82)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:376)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:291)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:243)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:164)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

Thanks for advance.

delete flag offensive retag edit

2 Replies

Sort by » oldest newest

answered 2010-12-29 04:17:27 +0800

vergereau gravatar image vergereau
105 1 2

Hello,

Can you try this :

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./winArticolo"?>



I think it's better to separate your component with the load of data by using a real controller

Example :
Controller
public class ArticleController extends GenericForwardComposer{

protected Listbox lb1;
List <Articolo > articoli = new ArrayList<Articolo >(); 

public ArticleController(){
articoli =...

}

// getter 
}



ZUL

<?xml version="1.0" encoding="UTF-8"?> 
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./winArticolo"?>

<window id="winArticolo" apply="com.xxx.ArticleController">
....

<listbox Width="1060px" id="lb1" model="@{winArticolo$composer.articoli}" >
...
</listbox>
</window>



Regards V,

link publish delete flag offensive edit

answered 2010-12-29 06:01:36 +0800

markdamne gravatar image markdamne
33

I solved it by restoring the libraries .. thank vergereau

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-12-24 04:27:03 +0800

Seen: 451 times

Last updated: Dec 29 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More