since you are using a button the listview has to be inside a form also,
Button bb = new Button(DEL) { public void onSubmit() { super.onSubmit(); // this is wrong, you should remove the item from the list and let the listview refresh rather then removing the wicket component - when listview redraws the item will be recreated... listviewlist.remove(custel); <== make sure your equals/hashcode is properly implemented } }; bb.setdefaultformprocessing(false); <== you dont want validation,etc. item.add(bb); try the changes above and i suggest you read the wiki page on models... -igor On Tue, Feb 26, 2008 at 10:31 PM, Martin Makundi <[EMAIL PROTECTED]> wrote: > It pretty much takes just that copy pasted code and the populateItem > below. Here is also the HTML: > > > protected void populateItem(final ListItem item) { > CustomElement custel = (CustomElement) item.getModelObject(); > item.add(new Label(START_DATE, new Model("dummy"))); > item.add(new Label(END_DATE, new Model("dummy"))); > { > TextField textField = new TextField(DESCRIPTION, new Model("Dummy")); > item.add(textField); > } > { > TextField textField = new TextField(DAYS, new Model("2")); //Dummy > item.add(textField); > } > { > Button bb = new Button(DEL) { > /** > * @see org.apache.wicket.markup.html.form.Button#onSubmit() > */ > @Override > public void onSubmit() { > super.onSubmit(); > item.remove(); > } > }; > item.add(bb); > } > } > > > > <html xmlns:wicket="http://wicket.sourceforge.net"> > <body> > <h2>Add a new period</h2> > <span wicket:id="feedback">Feedback messages will be here.</span> > <form name="testForm" wicket:id="testForm"> > Start - end: <input type="text" wicket:id="endDate" size="10"/> - > <input type="text" wicket:id="startDate" size="10"/> > Description: > <input type="text" wicket:id="description" size="40"/> > <input type="submit" value="Add"> > <h3>Current elements:</h3> > <table cellspacing="2" cellpadding="0" border="0"> > <thead> > <tr> > <th align="center">Start date</th> > <th align="center">End date</th> > <th align="left">Description</th> > <th align="center">Days</th> > <th align="center">Delete</th> > </tr> > </thead> > <tbody> > <tr wicket:id="listView"> > <td align="right" NOWRAP><span wicket:id="startDate"></span></td> > <td align="right" NOWRAP><span wicket:id="endDate"></span></td> > <td><input type="text" wicket:id="description" size="70"/></td> > <td><input type="text" wicket:id="days" size="70"/></td> > <td><input type="button" wicket:id="del" value="Del"/></td> > </tr> > </tbody> > </table> > </form> > </body> > </html> > > > > > > > > > 2008/2/27, Igor Vaynberg <[EMAIL PROTECTED]>: > > create a quickstart and i can take a look > > > > -igor > > > > > > On Tue, Feb 26, 2008 at 10:19 PM, Martin Makundi > > > > <[EMAIL PROTECTED]> wrote: > > > Funny. This works only if: > > > a) the listView is embedded in a Form component. (I would think it can > > > be independent) > > > b) the listView is not empty to begin with. If it is empty to begin > > > with, the new elements will not appear. If it is populated with 1 item > > > in the beginning, adding items will work fine. > > > > > > So.. am I still doing something wrong? > > > > > > > > > Code is trivial: > > > > > > public class MyPage extends WebPage { > > > > > > public MyPage() { > > > Form f = new MyForm(); > > > listViewElements = new LinkedList(); > > > listViewElements.add(new CustomElement()); // If I add a dummy > > > initial element, the added elements work fine. Otherwise not > > > ListView l = new ListVIew(.., new PropertyModel(this, > listViewElements)); > > > f.add(l); // Otherwise it does not work at all without setting the > > > form as its parent; strange > > > > > > } > > > > > > class MyForm() { > > > onSubmit() { > > > listViewElements.add(new CustomElement()); > > > info("Successful."); > > > } > > > } > > > } > > > > > > 2008/2/27, Igor Vaynberg <[EMAIL PROTECTED]>: > > > > > > > > > > try > > > > > > > > ListView l = new ListVIew(.., new propertymodel(this, > "listViewElements")); > > > > > > > > -igor > > > > > > > > > > > > On Tue, Feb 26, 2008 at 9:41 PM, Martin Makundi > > > > > > > > <[EMAIL PROTECTED]> wrote: > > > > > > your listview model is probably caching the old list, and > > > > > > thus when it redraws you dont see the new items. paste your > code and > > > > > > we can help you more. > > > > > > > > > > This is exactly what is happening. The listView is populated at > the > > > > > Page constructor. If the page is reloaded after onSubmit, the > > > > > constructor is not called again because the page is already > > > > > instantiated. Code is trivial: > > > > > > > > > > public class MyPage extends WebPage { > > > > > > > > > > public MyPage() { > > > > > Form f = new MyForm(); > > > > > listViewElements = new LinkedList(); > > > > > ListView l = new ListVIew(.., listViewElements); > > > > > } > > > > > > > > > > class MyForm() { > > > > > onSubmit() { > > > > > listViewElements.add(new CustomElement()); > > > > > info("Successful."); > > > > > // here I would like to acknowledge that the listView > > > > > // should be repainted to include the new element; > otherwise > > > > > the old listView is shown > > > > > > > > > > > > > > > } > > > > > } > > > > > } > > > > > > > > > > > > > > > > > -igor > > > > > > > > > > > > > > > > > > > > > > > > On Tue, Feb 26, 2008 at 8:50 PM, Martin Makundi > > > > > > <[EMAIL PROTECTED]> wrote: > > > > > > > Hi! > > > > > > > > > > > > > > Is it possible to refresh a listView during a form > onSubmit event, > > > > > > > without using ajax? Is there any way (apart from ajax) to > do it than > > > > > > > by explicitly reloading the page? > > > > > > > > > > > > > > If I reload the page I must store the feedback messages > elsewhere > > > > > > > (session-scope feedback messages) and re-initialize all > the components > > > > > > > "manually". Or is there maybe something like > listView.repaint() or > > > > > > > page.refresh() which can be called from Form.onSubmit()? > > > > > > > > > > > > > > This is what I have: > > > > > > > > > > > > > > <feedback messages here/> > > > > > > > Item: [ ] (textfield) ["Add" > Submit-button] > > > > > > > > > > > > > > <table> > > > > > > > <tr>previously added item</tr> > > > > > > > <tr>previously added item</tr> > > > > > > > <tr>previously added item</tr> > > > > > > > </table> > > > > > > > > > > > > > > This is what I want: > > > > > > > > > > > > > > When the "Add" -button is pressed, the form.onSubmit() is > called and a > > > > > > > new element is added into the list of elements (used as > the source for > > > > > > > the listView pupulating the table). I would then like to > "reload" the > > > > > > > page and show a success message in the feedback panel. > > > > > > > > > > > > > > I know this can be maneuvered by actually reloading the > page and using > > > > > > > session-scope feedback messages, but is there some "soft > reload", > > > > > > > which sort-of shortcuts using session-scope feedback > messages? > > > > > > > > > > > > > > Technically the difference is small, but conceptually I > find "soft > > > > > > > refresh" more intuitive. > > > > > > > > > > > > > > ** > > > > > > > Martin > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]