0

Dynamic Tabbox/Grid

asked 2007-10-28 12:54:42 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4592368

By: heidiatwork

Hi,
I'm new to zk and have the following problem, searching for an example:

I have a Tabbox with several tabs, f.e. Tab1, tab2, tab3..

For each tab I have to present a grid with several columns and rows (given through a Hashmap with <Tabname, arraylist> values. Arraylist represent the data which have to be shown in the given tabname.

can you please give an example how to do this?
thx a lot...
Heidi


delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2007-10-28 20:22:38 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4592770

By: oberinspector

Hello Heidi,

there is of course a way doing it in zul with nested ForEach, but i prefer to do such things directly in Java. I would create a subclass of Tabbox:

/************************************************************/
package my.package;

import java.util.ArrayList;
import java.util.Map;

import org.zkoss.zul.Column;
import org.zkoss.zul.Columns;
import org.zkoss.zul.Grid;
import org.zkoss.zul.Row;
import org.zkoss.zul.Rows;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Tabbox;
import org.zkoss.zul.Tabpanel;
import org.zkoss.zul.Tabpanels;
import org.zkoss.zul.Tabs;

public class MyTabbox extends Tabbox{

public void setDataMap(Map<String, ArrayList>data){
Tabs tabs = new Tabs();
Tabpanels tabpanels = new Tabpanels();

//iterate over Map keys
for(String tabname: data.keySet()){
Tab tab = new Tab(tabname);
tabs.appendChild(tab);


ArrayList al = data.get(tabname);

Grid grid = new Grid();
Columns columns = new Columns();
Column column1 = new Column();
Column column2 = new Column();

columns.appendChild(column1);
columns.appendChild(column2);
grid.appendChild(columns);

Rows rows = new Rows();

//iterate over ArrayList
for(Object obj: al){
Row row = new Row();
//TODO: create column 1 and 2 Components for this row
// depending on your data obj and append to this row
rows.appendChild(row);
}
grid.appendChild(rows);

Tabpanel tabpanel = new Tabpanel();
tabpanel.appendChild(grid);
tabpanels.appendChild(tabpanel);
}

this.appendChild(tabs);
this.appendChild(tabpanels);
}
}
/***************************************/

In ZUL you can write:

<zscript>
Map myData = getDataMap();
...
</zscript>
<window>
<tabbox use="my.package.MyTextbox" data="${myData}"/>
...
</window>


it's a little bit Quick&Dirty and not tested...

Good luck!

regards,
Thomas

link publish delete flag offensive edit

answered 2007-10-30 14:29:29 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4596284

By: heidiatwork

Hi Thomas,
thanks for the "quick&dirty" example, it works very fine!
Now I have a second prob: I want to add another grid to same tabpanel in the above example. my code (added before the other grid):

Grid grid0 = new Grid();
Rows rows0 = new Rows();
Row row0 = new Row();
Label labelWeak = new Label();
labelWeak.setValue("Weak Signal");
labelWeak.setParent(row0);
Label labelWeakValue = new Label();
labelWeakValue.setValue(al.get(0).getWeakSignalAsString());
labelWeakValue.setParent(row0);
grid0.appendChild(rows0);
...
tabpanel.appendChild(grid0);
...

But this grid isn't shown. Where's the problem????
Many thxs for your help....


link publish delete flag offensive edit

answered 2007-10-30 18:00:06 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4596641

By: oberinspector

Hello Heidi,

hmmm... when you do it while creation it should work... when you do it in an event handler you might have to invalidate the tabpanel to force recreation of the tabpanel... (tabpanel.invalidate()); As i believe setParent() and appendChild() do the same thing - i prefer to use append child. You used both ways in the same code... maybe you should try appendChild...

When you uses fixed sizes for the tabpanel dimensions the grid0 might be outside the visual area of the tabpanel... if you want to put the secont grid under the first you have to put both in a vbox.

when you use eclipse you can follow and check the Component creatieon in the debugger...

again GOOD LUCK!

regards,
Thomas



link publish delete flag offensive edit

answered 2010-03-15 04:48:02 +0800

rotkad gravatar image rotkad
18

updated 2010-03-15 07:44:49 +0800

Hi,
I tried to use a tabbox solution but it doesn't work for me.
I created MyTabbox class: (this is tabboxes in each tabs, but it's not the point)

public class MyTabbox extends Tabbox{
public void setCourseData(List<Chapter> data){
Tabs tabs = new Tabs();
Tabpanels tabpanels = new Tabpanels();
if(data!=null){
for(Chapter tabname : data){
Tab tab = new Tab(tabname.getTitle());
tabs.appendChild(tab);
Tabbox tabbox2 = new Tabbox();
Tabs tabs2 = new Tabs();
Tabpanels tabpanels2 = new Tabpanels();
for(Lesson l : tabname.getLessons()){
Tab tab2 = new Tab(l.getTitle());
tabs2.appendChild(tab2);
Tabpanel tabpanel2 = new Tabpanel();
tabpanels2.appendChild(tabpanel2);
}
Tabpanel tabpanel = new Tabpanel();
tabpanel.appendChild(tabbox2);
tabpanels.appendChild(tabpanel);
}
}
}
}

and I want to use it in zul file:
<zscript>
List list = ....... //what here if I want it created during application is runnig? The above solution is static.
</zscript>

<tabbox use="mypackage.MyTabbox" courseData="${list}">
what am I missing if ${list} should be created dynamically after users choice.

Problem solved

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: 2007-10-28 12:54:42 +0800

Seen: 1,307 times

Last updated: Mar 15 '10

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