ZK Component with independent columns -
i new zk framework[newbie] version 5.0.8 m.v.c approach trying implement component columns independent each other.... wanna able represent data on 2 columns , able respond click on each column
something like
----------------------------------- company----company oracle ibm microsoft xerox hp apple -----------------------------------
if click ibm want not click oracle.....[in same component mean dont want create 2 grid or 2 listbox or else]
is possible? lot.
it's not clear need in terms of independence here. looking separation in terms of data model or want different event listeners each rendered cell?
regarding event listeners, it's easy attach listeners you'd like. in zk, htmlbasedcomponent 1 of common root components , support onclick
, ondoubleclick
, onrightclick
, , more.
as these zk components being created dynamically, can't wire event listeners @listen
annotation. problem don't have id cells in advance.
instead, need programmatically create eventlistener
render.
// in rowrenderer public void render(row row, data data, int index) { label column1 = new label(data.getone()); label column2 = new label(data.gettwo()); column1.setparent(row); column2.setparent(row); column1.addeventlistener(events.on_click, new eventlistener<event>() { public void onevent(event event) { // handle event } }); column2.addeventlistener(events.on_click, new eventlistener<event>() { public void onevent(event event) { // handle event } }); }
note implemented here, create new eventlistener
every cell rendered. not efficient if can make eventlistener
stateless , attach necessary data label
itself, can save lot of computation.
regarding separation of code, if data model column oriented rather row, won't find standard zk component caters this. say, components grid
, listbox
rendered rows starting @ top using rowrenderers
, like. if problem, you'll want roll own component. lot easier might sound.
public class columngrid extends hlayout { private columnlistmodel model; private columnrenderer<? extends component> renderer; public void setmodel(columnlistmodel model) { this.model = model; } public void setrenderer(columnrenderer renderer) { this.renderer = renderer; } public void oncreate() { (int i=0; i<model.size(); i++) { column col = new column(); appendchild(col); renderer.render(col, model.getelementat(i), i); } } } public class column extends vlayout {} public interface columnrenderer<t extends component> { render(column column, t data, int index); }
it's skeleton, idea.
you can use in zul
files:
<?component name="colgrid" class="com.sean.is.cool.columngrid" ?> <colgrid model="mymodel" renderer="mycolrenderer"/>