-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm usign ZK 5.0 and i want to build a grid with dynamic columns and dynamic data. I have a pojo called Page, this has a List<PageRow> fmember and every PageRow has a List<PageField> fields member. I have a zul page with a grid and in his controller class i set the model in this way:
Page page = mycode...return...
ListModelList model = new ListModelList(page.getPageRows());
mygrid.setModel(model);
in zul page i have:
<grid id="mygrid">
<rows>
<row self="@{each=item}" value="@{item}">
<custom-attributes campi="@{item.fields}" composite="list"/>
<label value="@{each}" forEach="@{campi}" ></label>
</row>
</rows>
But i have a resulting grid with all the rows but only a column with no value inside. Where i'm wrong?
It's possible draw this grid with zul page mixin with java code in controller, or i must create the grid programmatically only in java code??
Please i have this :
private ListModel createModel() {
List data = new ArrayList();
List<Article> listArticle = new ArrayList<Article>();
List articleList = articleDAO.getListAllArticles();
for (int i = 0, j = articleList.size(); i < j; i++) {
//String article =((Article) articleList.get(i)).getNomArticle();
Article article = (Article) articleList.get(i);
List ParagList = paragDAO.getListParagByArticleO(article);//List ParagList = paragDAO.getListParagByArticleO((Article) (articleList.get(i)));
for (int k = 0, l = ParagList.size(); k < l; k++) {
//String parag = ((Paragraphe) ParagList.get(k)).getNomParag();
Paragraphe parag = (Paragraphe) ParagList.get(k);
List LigneList = ligneDAO.getListLignesByParag(parag);//List LigneList = ligneDAO.getListLignesByParag((Paragraphe) ParagList.get(k));
for (int m = 0, n = LigneList.size(); m < n; m++) {
Ligne ligne = (Ligne) LigneList.get(m);
data.add(article,parag,ligne), // adding objects is not possible.... i should change the data type.
}
}
please have you any idéa ?
You can add a Object array
data.add(Object []{article,parag,ligne});
and render them in renderer
public Row newRow(Grid grid) { Row row = new Row(); curData = getData(grid.getModel()); ............ Article article = (Article) curData[0]; ............ return row; }
Hi as1225...Sorry for being so "noisy" ...
I did all the changes but in the end i have this exception :
exception
org.zkoss.zk.ui.UiException: Only one rows child is allowed: <Grid cZLQ1> Note: rows is created automatically if live data org.zkoss.zul.Grid.beforeChildAdded(Grid.java:1187) org.zkoss.zk.ui.AbstractComponent.insertBefore(AbstractComponent.java:1082) org.zkoss.zul.Grid.insertBefore(Grid.java:1212)
in the Zul file i remover <row>....i onlly have <rows>
Can you show me the newRow(Grid grid) method ?
public Row newRow(Grid grid) { Row row = new Row(); curData = getData(grid.getModel()); boolean isNextArticle = !(prevArticle instanceof Article); boolean isNextSubArticle = !(prevParag instanceof Paragraphe); //boolean isNextSubArticle = !prevParag.equals(curData[1]); System.out.println("RowRenderer "+ curData.toString()); Map arg = new HashMap(); // first row of each Paragraphe if (isNextSubArticle) { // first row of each article if (isNextArticle) { Cell cell = new Cell(); prevArticle = (Article) curData[0]; cell.setRowspan(articleDAO.getTotalLignesCount(prevArticle)); cell.appendChild(new Label(prevArticle.getNomArticle())); row.appendChild(cell); } prevParag =(Paragraphe) curData[1]; Cell cell = new Cell(); cell.setRowspan((ParagrapheDAO.getListLigne(prevParag)).size()); System.out.println(" Ceeeell "+(ParagrapheDAO.getListLigne(prevParag)).size()); System.out.println(" object"+ prevParag.getNomParag()); cell.appendChild(new Label(prevParag.getNomParag())); row.appendChild(cell); } return row; }
Why do not use equals ?
boolean isNextArticle = !(prevArticle instanceof Article); boolean isNextSubArticle = !(prevParag instanceof Paragraphe); //boolean isNextSubArticle = !prevParag.equals(curData[1]);
I did it like that :
Row row = new Row(); curData = getData(grid.getModel()); boolean isNextArticle = !prevArticle.equals(curData[0]); boolean isNextSubArticle =!prevParag.equals(curData[1]);
But it results an ERROR :
2 mai 2011 12:05:40 org.zkoss.zk.ui.metainfo.Property assign:175 GRAVE: Failed to assign [model=${model}] to <Grid t6IQ1> Exception inconnue: java.lang.reflect.InvocationTargetException. 2 mai 2011 12:05:40 org.apache.catalina.core.StandardWrapperValve invoke GRAVE: "Servlet.service()" pour la servlet zkLoader a généré une exception java.lang.NullPointerException at ma.ensao.pfa.Handler.TableauHD$MyRowRenderer.newRow(TableauHD.java:72) at org.zkoss.zul.impl.GridDataLoader.newRow(GridDataLoader.java:165) at org.zkoss.zul.impl.GridDataLoader.newUnloadedItem(GridDataLoader.java:153) at org.zkoss.zul.impl.GridDataLoader.syncModel(GridDataLoader.java:301) at org.zkoss.zul.Grid.setModel(Grid.java:751) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
You have to initialize the variable
Object prevArticle = new Object(); .....
Asked: 2010-02-09 08:33:38 +0800
Seen: 10,702 times
Last updated: Nov 15 '12