0

Dynamic grid creation

asked 2010-02-09 08:33:38 +0800

maurix gravatar image maurix
9 1 1 1

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??

delete flag offensive retag edit

35 Replies

Sort by » oldest newest

answered 2011-04-27 07:21:06 +0800

EznatiZK gravatar image EznatiZK
60

............... I really do not get it !
could you exmplain the workflow?
AM using MVC (Bean,Handler,DAO)
Thanks

link publish delete flag offensive edit

answered 2011-04-27 13:46:29 +0800

EznatiZK gravatar image EznatiZK
60

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 ?

link publish delete flag offensive edit

answered 2011-04-27 20:05:52 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

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;
}

link publish delete flag offensive edit

answered 2011-04-28 12:54:15 +0800

EznatiZK gravatar image EznatiZK
60

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>

link publish delete flag offensive edit

answered 2011-04-28 13:42:56 +0800

EznatiZK gravatar image EznatiZK
60

I removeed even the <rows> tag and it worked... but tthe data listed is not coherent!
it lists only articles that hav SubArticles and only SubArticles that have SubSubArticles....

link publish delete flag offensive edit

answered 2011-04-28 20:23:25 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Can you show me the newRow(Grid grid) method ?

link publish delete flag offensive edit

answered 2011-04-29 07:18:27 +0800

EznatiZK gravatar image EznatiZK
60

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;
				}

link publish delete flag offensive edit

answered 2011-05-01 22:14:44 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Why do not use equals ?

boolean isNextArticle = !(prevArticle instanceof Article);
boolean isNextSubArticle = !(prevParag instanceof Paragraphe);
//boolean isNextSubArticle = !prevParag.equals(curData[1]);

link publish delete flag offensive edit

answered 2011-05-02 06:09:31 +0800

EznatiZK gravatar image EznatiZK
60

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)

link publish delete flag offensive edit

answered 2011-05-02 19:53:09 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

You have to initialize the variable

Object prevArticle = new Object();
.....

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-02-09 08:33:38 +0800

Seen: 10,702 times

Last updated: Nov 15 '12

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