You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by triswork <tr...@gmail.com> on 2009/03/10 20:28:42 UTC
Updating Main Page From Modal Using AJAX
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-tp22441758p22441758.html
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
Re: Updating Main Page From Modal Using AJAX
Posted by dtoffe <dt...@yahoo.com.ar>.
Hi,
I'm doing just what you explained, but the modal window content is a
page instead of a panel.
The Ajax debug window shows an error indicating that the component I'm
trying to update was not found:
ERROR: Component with id [[beanForm423]] a was not found while trying to
perform markup update. Make sure you called
component.setOutputMarkupId(true) on the component whose markup you are
trying to update.
component.setOutputMarkupId(true) is already there, but in the main
page, not in the page contained in the modal window.
Is there any way of making it work in this case, other than rewriting
the contained page to a panel ??
Thanks,
Daniel
tbt wrote:
>
>
> once the add button is clicked the users inside the modal window will be
> displayed on the main page.
>
>
--
View this message in context: http://www.nabble.com/Updating-Main-Page-From-Modal-Using-AJAX-tp22441758p22489608.html
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
Re: Updating Main Page From Modal Using AJAX
Posted by tbt <na...@yahoo.com>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org