Re: AW: Dynamically choosing component to add
Many thanks. I am also trying to add new textfield to the page when user clicks on a button. How can I do that? Is there any proper way? - Wicket-Java -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-choosing-component-to-add-tp3955869p4118343.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
Re: AW: Dynamically choosing component to add
I have tried this example so it is working perfect :) Thank you for your support. - Wicket-Java -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-choosing-component-to-add-tp3955869p4116037.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
Re: AW: Dynamically choosing component to add
Hi, I think I just responded to you in your own thread - where I didn't know what you were trying to do. I still don't claim to fully understand, but I think I better understand your question here. If you mean that you have one panel that *may possibly contain any one of X panels*, then here's one solution: ContainingPanel.html: wicket:panel Some markup here Blah, blah, blah... div wicket:id=childPanel/div More surrounding markup... /wicket:panel ContainingPanel.java: class ContainingPanel extends Panel { public void onBeforeRender() { if(getModelObject() is of some type) { addOrReplace(new SomePanel(childPanel)); } else if(getModelObject() is of some other type) { addOrReplace(new SomeOtherPanel(childPanel)); } } } You only need one wicket:id in your containing panel. You just swap at runtime which component actually shows up in that spot. I did almost exactly as Jeremy mentioned. Here is what I use: public void onBeforeRender() { Component component = get(childPanel); if(getModelObject() is of some type) { if(component instanceof SomePanel == false) addOrReplace(new SomePanel(childPanel)); } else if(getModelObject() is of some other type) { if(component instanceof SomeOtherPanel == false) addOrReplace(new SomeOtherPanel(childPanel)); } } As you can see, the difference is that I don't replace the component if it's already of the correct type. This is important if SomePanel or SomeOtherPanel contains state. Without my modifications, when the parent container is rendered, the child panels will always be reset to its initial state. Bertrand - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: AW: Dynamically choosing component to add
Hi Bertrand, I have almost the same problem you do (i think, im still a newbie). I'm trying to create a component that creates one specific container, depending on it's type. So i'd like to add only this container. I'm having problem at the .html, since i don't know if i should declare all wicket:id=idContainer or just the chosen one, since each container have it's own .html, how to 'link' the component html to the container .html. I want to know what you did on your .html, 'cause since your adding only the chosen panel to add, how you declared all possible panels on the .html? i wonder if you declared all panels on the .html or only the chosen one... Sorry for bad english, Thanks. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamically-choosing-component-to-add-tp3955869p4108449.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
Re: AW: Dynamically choosing component to add
On Fri, Nov 25, 2011 at 1:26 PM, Fabiosakiyam fabiosakiy...@gmail.comwrote: Hi Bertrand, I have almost the same problem you do (i think, im still a newbie). I'm trying to create a component that creates one specific container, depending on it's type. So i'd like to add only this container. I'm having problem at the .html, since i don't know if i should declare all wicket:id=idContainer or just the chosen one, since each container have it's own .html, how to 'link' the component html to the container .html. I want to know what you did on your .html, 'cause since your adding only the chosen panel to add, how you declared all possible panels on the .html? i wonder if you declared all panels on the .html or only the chosen one... I think I just responded to you in your own thread - where I didn't know what you were trying to do. I still don't claim to fully understand, but I think I better understand your question here. If you mean that you have one panel that *may possibly contain any one of X panels*, then here's one solution: ContainingPanel.html: wicket:panel Some markup here Blah, blah, blah... div wicket:id=childPanel/div More surrounding markup... /wicket:panel ContainingPanel.java: class ContainingPanel extends Panel { public void onBeforeRender() { if(getModelObject() is of some type) { addOrReplace(new SomePanel(childPanel)); } else if(getModelObject() is of some other type) { addOrReplace(new SomeOtherPanel(childPanel)); } } } You only need one wicket:id in your containing panel. You just swap at runtime which component actually shows up in that spot. -- Jeremy Thomerson http://wickettraining.com *Need a CMS for Wicket? Use Brix! http://brixcms.org*
Re: AW: Dynamically choosing component to add
Thank you Sven! On 31/10/2011 11:19 AM, Sven Meier wrote: onBeforeRender() and addOrReplace() are the right combination. Note that according to the javadoc you're not supposed to alter the component hierarchy in onConfigure(). Sven -Ursprüngliche Nachricht- Von: Bertrand Guay-Paquet [mailto:ber...@step.polymtl.ca] Gesendet: Montag, 31. Oktober 2011 15:35 An: users@wicket.apache.org Betreff: Re: Dynamically choosing component to add Thanks for the answer, but that is not what I am looking for. I already know how to replace a component with another one. My question is: I need to access a model's object to know which panel to add to a page (a persisted user preference). Since I shouldn't access a model's object in a component's constructor, when (onBeforeRender, onConfigure) should I do it to add the proper panel to the page? Using addOrReplace could very well be part of the overall solution, but this does not answer my core question. On 31/10/2011 9:54 AM, manuelbarzi wrote: MarkupContainer addOrReplace :? . On Mon, Oct 31, 2011 at 2:49 PM, Bertrand Guay-Paquet ber...@step.polymtl.ca wrote: Hi, Was is the proper way to choose which panel to add to a page based on a model's object value? Currently, I directly access the model and check the value during construction of the page. However, this is wrong since a model's object shouldn't be accessed until component rendering (see thread LDMs load too early - hold outdated application data). One obvious approach is to add all possible panels to the page and override their isVisible() method to inspect the model objects. This seems like wasted processing and memory so I'd like to avoid it. The page's onConfigure() and onBeforeRender() methods are the candidates I can think of to inspect the model object's value and add the proper panel. Is one better or is there another solution? Are there other issues with this approach? Regards, Bertrand --**--**- To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.orgusers-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 - 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