Saturday, 15 May 2010

wicket - Why a seperate markup identifier for a container and for the fragment? -



wicket - Why a seperate markup identifier for a container and for the fragment? -

can add together multiple fragments container? apparently not, why need seperate markup identifier container, , 1 fragment?

in html,

<div wicket:id="container"></div> <div wicket:id="container2"></div> <wicket:fragment wicket:id="myfragment"> <h3 wicket:id="dexter"></h3> <h3 wicket:id="deedee"></h3> </wicket:fragment> <wicket:fragment wicket:id="myotherfragment"> <h3 wicket:id="foo"></h3> <h3 wicket:id="bar"></h3> </wicket:fragment>

the web page,

public class mypage extends webpage { private component container; public mypage() { container=new myfragment("container",this); add(container); container=new myotherfragment("container2",this); add(container);

one of fragents (the other alike),

public myfragment(string id,webpage page) { super(id,"myfragment",page); label label=new label("dexter", "omelette du fromage"); add(label); label label2=new label("deedee","that's can say!"); add(label2); }

fragments meant easy reuse of little components, fill dynamic form or similar. when using fragment should utilize listview populate them. way can build dynamic markup. need reference fragment want utilize , tell wicket place in markup.

instead of 2 container divs, utilize list

<div wicket:id="fragmentlist"> <div wicket:id="fragment"></div> </div>

there no point in having 2 fragments same markup in (two h3 tags). instead can have header fragment , label fragment or whatever need.

<wicket:fragment wicket:id="headerfragment"> <h3 wicket:id="dexter"></h3> <h3 wicket:id="deedee"></h3> </wicket:fragment> <wicket:fragment wicket:id="labelfragment"> <label wicket:id="foo"></label> <label wicket:id="bar"></label> </wicket:fragment> <wicket:fragment wicket:id="inputfragment"> <label wicket:id="foo"></label> <input wicket:id="bar" type="text"> </wicket:fragment>

in webpage can add together fragments needed list of fragment , add together them listview

public homepage(final pageparameters parameters) { list<fragment> fragments = arrays.aslist(new headerfragment("fragment", this), new labelfragment("fragment", this), new inputfragment("fragment", this)); add(new listview<fragment>("fragmentlist", fragments) { @override protected void populateitem(listitem<fragment> item) { final fragment frag = _item.getmodelobject(); _item.add((fragment) frag); } }); }

wicket

No comments:

Post a Comment