Hi
try something like the following example given below.
on the main page display the user list as the following code.
public class UserPage extends WebPage
{
public UserPage()
{
ArrayList<String> userList = new ArrayList<String>();
userList.add("Adam");
userList.add("Nick");
userList.add("Paul");
ListView userListView = new ListView("userListView",userList)
{
@Override
protected void populateItem(ListItem item)
{
String user = (String) item.getModelObject();
item.add(new Label("user",user));
}
};
WebMarkupContainer webMarkupContainer = new
WebMarkupContainer("webMarkupContainer");
webMarkupContainer.add(userListView);
add(webMarkupContainer);
webMarkupContainer.setOutputMarkupId(true);
final ModalWindow modalWindow = new ModalWindow("modalWindow");
modalWindow.setOutputMarkupId(true);
modalWindow.setContent(new
UserPanel(modalWindow.getContentId(),userList,webMarkupContainer));
add(modalWindow);
add(new AjaxLink("ajaxLink")
{
public void onClick(AjaxRequestTarget target)
{
modalWindow.show(target);
}
});
}
}
next have a user panel to display inside the modal window
public class UserPanel extends Panel
{
public UserPanel(String id,final ArrayList<String> pageUserList,final
WebMarkupContainer webMarkupContainer)
{
super(id);
Form form = new Form("form");
ArrayList<String> userList = new ArrayList<String>();
userList.add("Steve");
userList.add("Amy");
userList.add("James");
ListView userListView = new ListView("userListView",userList)
{
@Override
protected void populateItem(ListItem item)
{
final String user = (String)
item.getModelObject();
item.add(new Label("user",user));
AjaxButton ajaxButton = new
AjaxButton("ajaxButton")
{
@Override
protected void
onSubmit(AjaxRequestTarget target, Form form)
{
pageUserList.add(user);
target.addComponent(webMarkupContainer);
}
};
item.add(ajaxButton);
}
};
form.add(userListView);
add(form);
}
}
once the add button is clicked the users inside the modal window will be
displayed on the main page.
triswork wrote:
>
> Hi
>
> I am having a problem that I hope someone can shed some light on.
> On my main page, I have a panel that simply displays a list of users
> (using a LinkedList as a model).
>
> Next to the panel, there is a link to open my modal window that contains a
> list of all my users. I am trying to implement a solution in which I can
> click that "add" button next to each user in the Modal window and have it
> populate the panel on the main page (without closing the window).
>
> I have tried a number of solutions without any success so far.
>
> My code looks something like this:
>
> public class MainPage() {
> private List<User> users = new LinkedList<User>();
> MainPage() {
> WebMarkupContainer wmc = new WebMarkupContainer("userPanelContainer");
> wmc.setOutputMarkupId(true);
> wmc.add(new UserPanel("userPanel", users)
> ...
> }
> }
>
> I have set the model of my UserPanel to my linked list and wrapped it with
> a WebMarkupContainer so that the panel can be easily replaced using AJAX.
>
> I then create my modal window like this:
> final ModalWindow userSelector = new ModalWindow("userSelector");
> and
> recipientSelector.setPageCreator(new ModalWindow.PageCreator() {
> public Page createPage() {
> return new RecipientSelectionWindow(MainPage.this.users,
> MainPage.this.wmc);
> }
> });
>
> The idea here being that I can add the user in my modal window to the
> underlying LinkedList<User> and have a handle to the wmc for any AJAX
> updates.
>
>
> In my modal window, I have the following onClick() method for my "add"
> link:
> public void onClick(AjaxRequestTarget target) {
> User selected = (User)getModelObject();
> userList.add(selected);
> if (target != null) {
> target.addComponent(markupContainer);
> }
> }
>
> I thought that this approach should be OK, but if fails miserably. The
> panel on the main page never updates. Even if I refresh the page manually
> (F5).
>
> The funny thing is though, that if I look at the AJAX DEBUG window, the
> response seems fine and the ID tags are all correct. I suspect that the
> AJAX response is being applied to my Modal window rather than my main
> page.
>
> If I use my debugger, I can see the underlying LinkedList<User> being
> updated too, but che changes are never displayed.
>
> I am quite new to wicket, so I expect that I am doing something really
> daft... I just can't figure out what it is. I am also sure that my
> current approach is not optimal. Any suggestions on the "correct" way to
> do this will also be greatly appreciated.
>
--
View this message in context:
http://www.nabble.com/Updating-Main-Page-From-Modal-Using-AJAX-tp22441758p22473023.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]