I've added http://www.wicket-wiki.org.uk/wiki/index.php/Using_repeaters, although I'm not sure if there's not an optimisation I'm missing involving a compound property model, as I've got a populateItem() like this...
protected void populateItem(ListItem item) { User user = (User)item.getModelObject(); item.add(new Label("firstname", user.getFirstname())); item.add(new Label("lastname", user.getLastname())); } It works though, so not critical... /Gwyn On 08/05/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
yeah, that would be helpful. maybe someone can do it :) between answering questsions here and working on wicket i have no spare time for the wiki. i am really counting on people whom i help to take the time and contribute back to the wiki. here is an old thread that might be of help, maybe someone can put it into a wiki http://www.nabble.com/ListView-tutorial--t981124.html#a2540514 and a good thread on models http://www.nabble.com/IModel-t947549.html#a2460182 -Igor On 5/7/06, Rivka Shisman <[EMAIL PROTECTED]> wrote: > > > > > Thanks Igor, > > > > This looks like what I need. > > A wiki page with an example can be very helpful indeed. > > > > Rivka > > > > ________________________________ > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Igor Vaynberg > Sent: Monday, May 08, 2006 3:12 AM > > To: wicket-user@lists.sourceforge.net > Subject: Re: [Wicket-user] dynamic html controls > > > > > > > > this is where you use a repeater ( a listview in core or a number of components in wicket-extensions repeaters package ) > > a repeater is wicket's way of doing loops. > > ie: > > List list=Arrays.asList(new String[] { "a","b","c")); > ListView listview=new ListView("listview", list) { > void populateItem(ListItem item) { > item.add(new Label("label", item.getModel())); > } > } > > <span wicket:id="listview"> > this label is: <span wicket:id="label">label</span><br/> > </span> > > will result in > <span wicket:id="label">a</span><br/> > <span wicket:id="label">b</span><br/> > <span wicket:id="label">c</span><br/> > > you can also put formcomponents into the repeaters, you bind their values through IModel just as if they were in a regular form. > > there are a few provisions you have to take care of when using a repeater in the form.usually repeaters clear out their items at the beginning of every request, when inside a form this is usually undesirable because you want to preserve the old items because you want them to keep their state as opposed to being recreated fresh. > > listview, for example, has ListView.setReuseItems(true); which should be called when inside the form so that it preserves old items instead of always creating new ones. > > hope this gets you started, this is a large topic and i would be happy to answer any more specific questions you have. meanwhile maybe someone can write up a general wiki page. > > -Igor > > > On 5/7/06, Bruno Borges <[EMAIL PROTECTED]> wrote: > > > I think I understand what Shisman wants: > > How to add, lets say here, a number of TextFields to a form dynamically, depending on something coming from the database. > > For example: > > int id = 0; > for(Contract c : contracts) { > String incrementId = "contract_" + id; > add(new TextField(incrementId, new Model(c.getNumber()))); > id++; > } > > Now, how to reference all those components in the html? > > Well, I don't have the answer for that. :D > > > > > > On 5/4/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote: > > > sure you can do that, but then you yourself have to manage request parameters, yuck. the whole point of components is that they take care of all that messy stuff for you. > > if you still want to do that you override webcomponent.onrender () and do something like this: getResponse().write("blah"); > > however, it seems to me you are still not thinking in terms of components. > > if you can give me a more defined usecase i can show you how to break it down into components > > for the general usecase you are talking about - ie lets say building a set of checkboxes for a collection that comes out of the database you can use our prebuilt component CheckBoxMultiChoice or you can use the more component oriented version CheckGroup/Check > > with CheckGroup/Check your component hierarchy would look like this > > CheckGroup - manages the group of avail checkboxes > | Repeater (ListView or another) - iterates over the list of items retrieved from the db > | | Check - checkbox representing a single item from the db list > | | | Label - a label to show text representing a single item from the db list > > in this way you can create a list of checkboxes for a list of variable length. > > does this clear things up a bit? > > > > > -Igor > > > > > On 5/4/06, Rivka Shisman <[EMAIL PROTECTED]> wrote: > > > > Hi Igor, > > > > I still don't understand where is the servlet functionality of Wicket. > > What if I don't want to hand code all my textboxes in the html and instead I want to dynamically add them with "out.print" like possibility from a collection with unknown size that comes from the database. > > > > If I use a panel (as much as I understand what a panel is) I still need it to be a dynamically built panel. > > > > Thanks > > Rivka > > > > ________________________________ > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Igor Vaynberg > Sent: Thursday, May 04, 2006 7:17 PM > > > > To: wicket-user@lists.sourceforge.net > Subject: Re: [Wicket-user] dynamic html controls > > > > > lets take your exact usecase, hiding and showing form components based on some condition. > > there are two basic strategies to do this: > > 1) add all of them an then toggle visibility > > this means you add all possible formcomponents and then override isVisible() on them or call setVisible(false). this will tell wicket not to render the portion of html associated with that component. > > so instead of <c:if condition="blah"><input type="text" name="comp" value="${val}"/></c:if> in jsp you would have > > add(new TextField("comp",...) { > boolean isVisible() { > return blah; > } > } > > and in html <input type="text" wicket:id="comp"/> > > > 2) swapping panels - this is usually used for bigger chunks of the page then formcomponents. a good analagy for this is the tabbed view. > > when you click a tab the body of the view has to change to show a different tab's body. each tab's body can be represented as a panel so when a tab is clicked it can swap the panel in the body of the tabbed panel with the panel of its chosing. > > see our TabbedPanel for example in code and in our component reference which shows a short example > > hope this helps, > > -Igor > > > > > On 5/4/06, Rivka Shisman < [EMAIL PROTECTED]> wrote: > > Hi Eelco, > > Do you mean that I should create a "panel" with a link to my own servlet > that shows the dynamic content? > > Thanks > Rivka > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Eelco > Hillenius > Sent: Thursday, May 04, 2006 10:21 AM > To: wicket-user@lists.sourceforge.net > Subject: Re: [Wicket-user] dynamic html controls > > You can do what is outlined here: > http://wicket-wiki.org.uk/wiki/index.php/Create_dynamic_markup_hierarchi > es_using_panels > > Or - like the article says, add all visible components and use the > isVisible property (or override the method) for turning them on or > off. > > Or use Fragments, which work like panels, but have their markup > definded in the same markup (HTML) file. > > Eelco > > On 5/4/06, Rivka Shisman <[EMAIL PROTECTED] > wrote: > > > > > > > > Hi > > > > > > > > I have no experience with Wicket, but from what I read about it I > don't > > understand where does the dynamic content part come in? > > > > If I have a pair of html file and a java file - how do I conditionally > > show/hide html form controls like I do in JSP? > > > > > > > > For example, I have a JSP page that constructs my form text fields > (and > > labels) from a result of a select from the database? > > > > Is that possible to achieve with Wicket? > > > > > > > > Thanks > > > > Rivka > > > > > > > > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 > _______________________________________________ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmdlnk&kid0709&bid&3057&dat1642 > _______________________________________________ > Wicket-user mailing list > Wicket-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/wicket-user > > > > > > > > > > > > > -- > Bruno Borges > [EMAIL PROTECTED] > Sun Certified Java Programmer for 1.4 > Sun Certified Web Component Developer for 1.4 > > >
------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user