I am trying to replace a panel with another panel.  The replacement
works the first time.  The next time I click on the replacement link, I
get an exception.

"java.lang.IllegalStateException: This method can only be called on a
component that has already been added to its parent."  

 

You will see I am trying to use jQuery .  The jquery piece seems to be
functioning correctly.  I am getting the accordion and also the dialog
popup.  I do notice that in the DOM I am getting 2 divs for the dialog
after the replacement.

 

 

Thanks.

 

Here is the java code for the page:

                                final WebMarkupContainer options = new
WebMarkupContainer("options");

                                options.setMarkupId("options");

                                options.setOutputMarkupId(true);

 
options.setOutputMarkupPlaceholderTag(true);

                                

                                final Panel testPanel = new
TabPanelStart("optPanel");

                                testPanel.setMarkupId("dialog");

                                testPanel.setOutputMarkupId(true);

 
testPanel.setOutputMarkupPlaceholderTag(true);

                                add(testPanel);

                                

                                final TabPanel2 panel2 = new
TabPanel2("panel2");

                                panel2.setOutputMarkupId(true);

 
panel2.setOutputMarkupPlaceholderTag(true);

                                

                                TabPanel3 panel3 = new
TabPanel3("panel3");

                                

                                TabPanel panel1 = new TabPanel("panel1")
{

                                                @Override

                                                void
setContent(AjaxRequestTarget target) {

                                                                

                                                                Panel
myPanel = new TestPanel(testPanel.getId()) {

 
@Override

 
public void refresh(AjaxRequestTarget target) {

 
target.addComponent(panel2);

 
target.addComponent(options);              

 
}

                                                                };

 
myPanel.setMarkupId("dialog");

 
myPanel.setOutputMarkupId(true);

 
testPanel.replaceWith(myPanel);

 
target.addComponent(myPanel);

                                                }

                                };

                                options.add(panel1);

                                options.add(panel2);

                                options.add(panel3);

                                add(options);

 

Here is the TabPanel class:

                public TabPanel(String id) {

                                super(id);

                                

                                AjaxLink link = new AjaxLink("link") {

 

                                                @Override

                                                public void
onClick(AjaxRequestTarget target) {

 
setContent(target);

 
target.appendJavascript("$e('#dialog').dialog({ autoOpen: false });");

 
target.appendJavascript("$e('#dialog').dialog('open');");

                                                }

                                };

                                add(link);

                }

                

                abstract void setContent(AjaxRequestTarget target);

 

Here is the TestPanel class:

                public TestPanel(String id) {

                                super(id);

                                

                                AjaxLink link = new AjaxLink("opt1") {

                                                @Override

                                                public void
onClick(AjaxRequestTarget target) {

 
refresh(target);

 
this.getSession().error("The user selected something in option 1");

 
target.appendJavascript("$e('#dialog').dialog('close');");

 
target.appendJavascript("$e(document).trigger('optionsUpdated');");

 
//target.appendJavascript("$e('#options').accordion( 'activate' , false
);");

 
target.appendJavascript("$e('#options').accordion( 'activate' , 1 );");

                                                }

                                };

                                add(link);

                }

                

                abstract public void refresh(AjaxRequestTarget target);

 

Reply via email to