I am using this behaviour because I found an example for this. I don't know if there is anything better. :)
Ok, the problem is I have some javascript diagrams (from http://highcharts.com/, don't want to advertise, but since you've asked ;)) that I use in our wicket app. and when I click on a part of the diagramm I want to open a wicket panel that loads data for that specific part of the diagramm. so I got everything working except the panel replacement. I also tried the MyPanel.this.addOrReplacecomponent(myAjaxLoadedPanel) before with no effect, but maybe I've screwed something else up then. Gonna try it again, thanks. On Sun, Jul 24, 2011 at 5:06 PM, Martin Grigorov <mgrigo...@apache.org> wrote: > On Sun, Jul 24, 2011 at 5:40 PM, Michael Petritsch > <michael.petrit...@gmail.com> wrote: >> Yes, I removed the visibility related code and anything else for >> simplicity and to focus on the actual problem. >> >> What I actually want to achieve is something like: >> >> public class MyPanel extends Panel { >> Panel myAjaxLoadedPanel; >> public MyPanel() { >> add(new AbstractDefaultAjaxBehavior() { > Still not clear why you use directly this behavior but you know better :-) >> @Override >> protected void respond(AjaxRequestTarget target) { >> String someParameter = >> RequestCycle.get().getRequest().getParameter("someParameter"); >> if(someParameter.equals("1") { > reverse the check here to avoid NPE >> myAjaxLoadedPanel = new Foo1Panel("myAjaxLoadedPanel"); >> } >> ... >> else { >> myAjaxLoadedPanel = new FooXPanel("myAjaxLoadedPanel"); >> } >> target.addComponent(myAjaxLoadedPanel); >> } >> } >> myAjaxLoadedPanel = new MyDefaultPanel("myAjaxLoadedPanel"); >> myAjaxLoadedPanel.setOutputMarkupId(true); >> add(myAjaxLoadedPanel); >> } > The problem that I see is that you just re-assign the panel. Better > see org.apache.wicket.Component.replaceWith(Component) and > org.apache.wicket.MarkupContainer.replace(Component). These methods > preserve the component hierarchy, i.e. the new assignment will > inherits its parent (MyPanel.this) from the old assignment. > > What is the actual problem ? Sorry, but I didn't follow this thread before. > >> >> On Sun, Jul 24, 2011 at 4:16 PM, Martin Grigorov <mgrigo...@apache.org> >> wrote: >>> On Sun, Jul 24, 2011 at 5:10 PM, Michael Petritsch >>> <michael.petrit...@gmail.com> wrote: >>>> I am using wicket 1.4.16, the markupplaceholder is there (checked with >>>> firebug). >>>> >>>> I have also tried it with a simple visible label: >>>> >>>> public class MyPanel extends Panel { >>>> Label myUpdatedLabel; >>>> public MyPanel() { >>>> add(new AbstractDefaultAjaxBehavior() { >>> Why do you use this behavior but not a more specific one ? E.g. >>> AjaxEventBehavior. >>>> @Override >>>> protected void respond(AjaxRequestTarget target) { >>>> myUpdatedLabel.setDefaultModel("bar"); >>>> target.addComponent(myUpdatedLabel); >>>> } >>>> } >>>> myUpdatedLabel = new Label("myLabel","foo"); >>>> myUpdatedLabel.setOutputMarkupId(true); >>>> add(myUpdatedLabel); >>>> } >>>> >>>> This works, however what I actually have to do in the response() >>>> method is the following: >>>> myUpdatedLabel = new Label("myLabel","bar"); >>>> myUpdatedLabel.setOuputMarkupId(true); >>>> target.addComponent(myUpdatedLabel); >>> What you really want is: >>> myUpdatedLabel.setDefaultModelObject("bar"); >>> target.addComponent(myUpdatedLabel); >>>> >>>> But when I try this nothing happens. The html of the label remains >>>> untouched: <div id="myLabeld" wicket:id="myLabel">foo</div> >>> setOutputMarkupPlaceholderTag(true) is needed only if you change the >>> visibility of Ajax updated component. I don't see visibility related >>> logic in your code. >>> >>> What exactly you want to achieve ? >>>> >>>> On Mon, Jul 18, 2011 at 4:59 AM, msj121 <msj...@gmail.com> wrote: >>>>> I am not sure if it is still true, but if you have the label added, just >>>>> the >>>>> visibility is false from the beginning, then in older versions of wicket >>>>> it >>>>> would not actually put the component, even the placeholder. I dealt with >>>>> this before, but I think in newer versions presumably this was changed.... >>>>> In theory a good way to check if this is an issue is to setvisible to true >>>>> in the beginning and alternate. >>>>> >>>>> >>>>> If your trying to add a new markup that never existed in html to the page, >>>>> it should throw an error, and then you will need to use ListViews etc... >>>>> as >>>>> described above. >>>>> >>>>> -- >>>>> View this message in context: >>>>> http://apache-wicket.1842946.n4.nabble.com/Loading-wicket-components-from-javascript-tp3673381p3674372.html >>>>> Sent from the Users forum mailing list archive at Nabble.com. >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>>> >>>>> >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>> >>>> >>> >>> >>> >>> -- >>> Martin Grigorov >>> jWeekend >>> Training, Consulting, Development >>> http://jWeekend.com >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >>> For additional commands, e-mail: users-h...@wicket.apache.org >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > > > -- > Martin Grigorov > jWeekend > Training, Consulting, Development > http://jWeekend.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org