You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by freak182 <em...@gmail.com> on 2008/12/16 13:09:33 UTC

Re: How to update parent component from a panel?

Hello,
I just got into this message just now...you know you have to play with
ajaxrequesttartget component...

For: Timo
  I want to ask if this "events" stuff is already available in wicket 1.3.5
release? if so, what classes should i look into?

Thank you for your help.




Lenka Laurincikova wrote:
> 
> Hello, 
> 
> I have followed this example. Thank you a lot, it is actually helped me.
> However even though I got refreshed component, the previous state of the
> component is still displayed. I have to refresh the page to remove it.
> 
> Any helping hint would be appreciated.
> 
> regards
> Lenka
> 
> 
> Timo Rantalaiho wrote:
>> 
>> On Mon, 09 Jun 2008, freak182 wrote:
>>> Im having problem of updating parents components.Hereis my problem,
>>> there is
>>> page and in that page there is a panel. The panel contain a
>>> FormUpdatingComponent that attached to a dropdownchoice. Now when the
>>> dropdown is triggered, i want to update the parents (the page)
>>> textbox/label..is this possible?
>> 
>> Hmm, what is FormUpdatingComponent?-) A typo perhaps?
>> 
>> Sure it is possible, e.g. something like
>> 
>> public class FooPage extends WebPage {
>>     public FooPage() {
>>         Panel fooPanel = new FooPanel("fooPanel", ... 
>>         ....
>> 	Foo initialSelection = ...
>> 	IModel fooModel = new Model(initialSelection);
>>         final Label display = new Label("foo", fooModel);
>> 	display.setOutputMarkupId(true);
>> 	add(display);
>> 	DropDownChoice selection = new DropDownChoice("fooSelection",
>>             fooModel, choices);
>>         selection.add(new AjaxFormComponentUpdatingBehavior("onchange) {
>> 	    public void onEvent(AjaxRequestTarget target) {
>> 	        target.addComponent(display);
>> 	    }
>> 	});
>> 	fooPanel.add(selection);
>> 	...
>>     }
>> }
>> 
>> But if your Panel is "further away" from the other
>> components directly on the page, this might get trickier.
>> For normal requests you can often get away with sharing the
>> model, but if passing it all the way to the "sending"
>> component gets nasty, or if you want to repaint something in
>> the parent via Ajax, something like this might be easier
>> 
>> public interface FooChoiceListener {
>>   void onSelection(IModel foo, AjaxRequestTarget target);
>> }
>> 
>> public class MyLabel extends Label implements FooChoiceListener {
>> ...
>>   public void onSelection(IModel foo, AjaxRequestTarget target) {
>>     setModelObject(foo.getObject());
>>     target.addComponent(this);
>>   }
>> }
>> 
>> 
>> public class FooPage extends WebPage {
>>   public FooPage() {
>>     Label display = new MyLabel(...);
>>     add(new FooPanel());
>>     ...
>>   }
>> }
>> 
>> public class FooPanel extends Panel {
>>   public FooPanel(String id, IModel foo) {
>>   ...
>>     DropDownChoice selection = new DropDownChoice("fooSelection",
>>       fooModel, choices);
>>     selection.add(new AjaxFormComponentUpdatingBehavior("onchange) {
>>       public void onEvent(AjaxRequestTarget target) {
>>         getPage().visitChildren(FooChoiceListener.class, 
>>            new IVisitor() {
>>              public Object component(Component c) {
>>                ((FooChoiceListener) c).onSelection(fooModel, target);
>>                return CONTINUE_TRAVERSAL;
>> 	     }
>> 	});
>>       }
>>     });
>>   }
>> }
>> 
>> A "generic eventbroadcaster" can be found here
>> 
>>   http://issues.apache.org/jira/browse/WICKET-1312
>> 
>> Best wishes,
>> Timo
>> 
>> -- 
>> Timo Rantalaiho           
>> Reaktor Innovations Oy    <URL: http://www.ri.fi/ >
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-update-parent-component-from-a-panel--tp17748294p21031933.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: How to update parent component from a panel?

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Tue, 16 Dec 2008, freak182 wrote:
>   I want to ask if this "events" stuff is already available in wicket 1.3.5
> release? if so, what classes should i look into?

No it's not, but you can just copy its code (or one of the
competing implementations :)) from the patches attached to
the Jira issue.

Probably it will be in some form in Wicket 1.5.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org