You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by juliez <ju...@yahoo.com> on 2007/08/31 17:04:14 UTC

Re: Update a ListView (Solved)

Just need to remember only the model get updated for each request. So after I
changed to code as follows, it works!

After:
PageableListView messageListView = 
    new PageableListView("messageTable", new PropertyModel(this,
"messages"), 5)
Before:
PageableListView messageListView = 
    new PageableListView("messageTable", messages, 5)

Julie 


juliez wrote:
> 
> I have a simple page to that contains an input box, a drop down list with
> a submit button and a table below it. When a user inputs something,
> chooses the item in the drop down list and hit the submit button, the
> table should be refreshed. It seems a lot like the GuestBook in the
> example.
> 
> I first implemented the table with AjaxFallbackDefaultDataTable with a
> list of AbstractColumn and it works well. But then I changed to use
> PagableListView and couldn't get the table content refreshed.
> 
> The code is like this (1, 2 and 3 are in one method, 4 is in another
> method)
> 0. In the constructor: initiate the instance variable of messages.
> messages = personService.doGetMessages(currentUser);
> 
> 1. The text area
> The model is an Object of Message class.
>         final IModel messageModel = new CompoundPropertyModel(new
> Message());
> 	form.add(new TextArea("message", new PropertyModel(messageModel,      
> "message")).setRequired(true));
> 
> 2. The drop down list
> The model is an Object of Person class which I retrieved from database.
> 	form.add(new DropDownChoice("receiver", 
>                 new PropertyModel(messageModel, "person"),
> 		new LoadableDetachableModel() {
> 			protected Object load() {
> 				return personService.doFindUsers();
> 			}
> 		},
> 		new ChoiceRenderer("formattedName")).setRequired(true));
> 
> 3. The button
> 	form.add(new Button("sendButton") {
> 		public void onSubmit() {
> 			Message message = (Message) messageModel.getObject();
> 			personService.doSendPersonMessage(message);
> 			message.setMessage("");
> 			messages = personService.doGetMessages(currentUser); //REFRESH THE LIST
> 		}
> 	});
> 
> 4. The List View
> The model is a list of Message(s)
> 	PageableListView messageListView = 
> 		new PageableListView("messageTable", messages, 5) {
> 			protected void populateItem(ListItem item) {
>  				Message message = (Message)item.getModelObject();
> 				item.add(new Label("messageContent", message.getMessage()));
> 			}
> 		};
> 	form.add(messageListView);
> 
> Question:
> a. The messages in the ListView hasn't been refreshed when it is refreshed
> in the onSubmit() in the button code. Why? 
> 
> b. In the button code (#3 in the code list), if I reset the model of the
> ListView in onSubmit() as follows to replace the refresh of messages, the
> table is refreshed. But I don't think it's the right way to do it, right?
> getParent().get("messageTable").setModelObject(personService.doGetMessages(currentUser));
> 
> c. What's the difference of using DataTable and ListView in Wicket? If
> it's discussed before, please just tell me this.
> 
> Thanks!
> Julie 
> 

-- 
View this message in context: http://www.nabble.com/Update-a-ListView-tf4355194.html#a12428138
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org