You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sibgha Nazir <si...@gmail.com> on 2019/05/26 13:33:15 UTC

Notify Action to the Parent Class

Hi,

In my application, Home Page creates DPanel and Dpanel has the drop down
menu.   In the class DPanel at 'onchange' event, I want to do some action
in the class HomePage.java. How can that be possible?


*HomePage.java*    public HomePage(final PageParameters parameters)
    {
        super(parameters);

        final Panel dropDownPanel = new Dpanel("toReplace");

        dropDownPanel.setOutputMarkupId(true);
        add(dropDownPanel);
    }


*DPanel.java*    public Dpanel(String aId)
    {
        super(aId);
        form = new Form<Void>("form");
        form.setOutputMarkupId(true);

        // SelectMenu //
        final DropDownChoice<String> dropdown = new
DropDownChoice<String>("select", new Model<String>(), new
ListModel<String>(GENRES));
        dropdown.setRequired(true);
        dropdown.setOutputMarkupId(true);
        dropdown.add(new AjaxFormComponentUpdatingBehavior("change") {
            /**
             *
             */
            private static final long serialVersionUID =
-6744838136235652577L;

            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println("Changed");

            }
        });
.
.
.
.

Quick Start here...
https://github.com/Sibgha360/dropdownexample.git,

Re: Notify Action to the Parent Class

Posted by Sebastien <se...@gmail.com>.
Hi,

François solution is based on the wicket event bus which is the recommanded
approach.

To broadcast to a parent component which might not be the page, you can use
:
send(this, Broadcast.BUBBLE)
Or even
send(getPage(), Broadcast.BREADTH)

You may also put a breakpoint in onEvent to verify it is reached with your
payload.

Thanks,
Sebastien

On Mon, May 27, 2019, 10:03 Sibgha Nazir <si...@gmail.com> wrote:

> Hey,
>
> I tried what you mentioned. The condition is never satisfied.
>
> *if (event.getPayload() instanceof YourEvent)  *
>
> On Sun, May 26, 2019 at 6:10 PM Francois Meillet <
> francois.meillet@gmail.com>
> wrote:
>
> > Hi Sibgha,
> >
> > // here is a simple code
> >
> > //
> > // in your Dpanel
> > //
> > protected void onUpdate(AjaxRequestTarget target) {
> >     send(getPage(), Broadcast.EXACT, new
> > YourEvent(yourDataFromYourDropDownChoice));
> > }
> >
> >
> > //
> > // in your HomePage, you override the onEvent method
> > //
> > @Override
> > public void onEvent(IEvent<?> event) {
> >     super.onEvent(event);
> >
> >     if (event.getPayload() instanceof YourEvent) {
> >
> >         YourEvent yourEvent = (YourEvent) = event.getPayload();
> >         // the data you sent throw your vent
> >         YourData xyz = yourEvent.getData();
> >         // if you don't neeed anymore your event
> >         event.stop();
> >     }
> > }
> >
> >
> > // look at the docs
> >
> >
> https://ci.apache.org/projects/wicket/guide/8.x/single.html#_wicket_events_infrastructure
> >
> >
> > François
> > follow Apache Wicket on twitter : https://twitter.com/apache_wicket <
> > https://twitter.com/apache_wicket> !
> >
> >
> > > Le 26 mai 2019 à 15:33, Sibgha Nazir <si...@gmail.com> a écrit :
> > >
> > > Hi,
> > >
> > > In my application, Home Page creates DPanel and Dpanel has the drop
> down
> > > menu.   In the class DPanel at 'onchange' event, I want to do some
> action
> > > in the class HomePage.java. How can that be possible?
> > >
> > >
> > > *HomePage.java*    public HomePage(final PageParameters parameters)
> > >    {
> > >        super(parameters);
> > >
> > >        final Panel dropDownPanel = new Dpanel("toReplace");
> > >
> > >        dropDownPanel.setOutputMarkupId(true);
> > >        add(dropDownPanel);
> > >    }
> > >
> > >
> > > *DPanel.java*    public Dpanel(String aId)
> > >    {
> > >        super(aId);
> > >        form = new Form<Void>("form");
> > >        form.setOutputMarkupId(true);
> > >
> > >        // SelectMenu //
> > >        final DropDownChoice<String> dropdown = new
> > > DropDownChoice<String>("select", new Model<String>(), new
> > > ListModel<String>(GENRES));
> > >        dropdown.setRequired(true);
> > >        dropdown.setOutputMarkupId(true);
> > >        dropdown.add(new AjaxFormComponentUpdatingBehavior("change") {
> > >            /**
> > >             *
> > >             */
> > >            private static final long serialVersionUID =
> > > -6744838136235652577L;
> > >
> > >            protected void onUpdate(AjaxRequestTarget target) {
> > >                System.out.println("Changed");
> > >
> > >            }
> > >        });
> > > .
> > > .
> > > .
> > > .
> > >
> > > Quick Start here...
> > > https://github.com/Sibgha360/dropdownexample.git,
> >
> >
>

Re: Notify Action to the Parent Class

Posted by Sibgha Nazir <si...@gmail.com>.
Hey,

I tried what you mentioned. The condition is never satisfied.

*if (event.getPayload() instanceof YourEvent)  *

On Sun, May 26, 2019 at 6:10 PM Francois Meillet <fr...@gmail.com>
wrote:

> Hi Sibgha,
>
> // here is a simple code
>
> //
> // in your Dpanel
> //
> protected void onUpdate(AjaxRequestTarget target) {
>     send(getPage(), Broadcast.EXACT, new
> YourEvent(yourDataFromYourDropDownChoice));
> }
>
>
> //
> // in your HomePage, you override the onEvent method
> //
> @Override
> public void onEvent(IEvent<?> event) {
>     super.onEvent(event);
>
>     if (event.getPayload() instanceof YourEvent) {
>
>         YourEvent yourEvent = (YourEvent) = event.getPayload();
>         // the data you sent throw your vent
>         YourData xyz = yourEvent.getData();
>         // if you don't neeed anymore your event
>         event.stop();
>     }
> }
>
>
> // look at the docs
>
> https://ci.apache.org/projects/wicket/guide/8.x/single.html#_wicket_events_infrastructure
>
>
> François
> follow Apache Wicket on twitter : https://twitter.com/apache_wicket <
> https://twitter.com/apache_wicket> !
>
>
> > Le 26 mai 2019 à 15:33, Sibgha Nazir <si...@gmail.com> a écrit :
> >
> > Hi,
> >
> > In my application, Home Page creates DPanel and Dpanel has the drop down
> > menu.   In the class DPanel at 'onchange' event, I want to do some action
> > in the class HomePage.java. How can that be possible?
> >
> >
> > *HomePage.java*    public HomePage(final PageParameters parameters)
> >    {
> >        super(parameters);
> >
> >        final Panel dropDownPanel = new Dpanel("toReplace");
> >
> >        dropDownPanel.setOutputMarkupId(true);
> >        add(dropDownPanel);
> >    }
> >
> >
> > *DPanel.java*    public Dpanel(String aId)
> >    {
> >        super(aId);
> >        form = new Form<Void>("form");
> >        form.setOutputMarkupId(true);
> >
> >        // SelectMenu //
> >        final DropDownChoice<String> dropdown = new
> > DropDownChoice<String>("select", new Model<String>(), new
> > ListModel<String>(GENRES));
> >        dropdown.setRequired(true);
> >        dropdown.setOutputMarkupId(true);
> >        dropdown.add(new AjaxFormComponentUpdatingBehavior("change") {
> >            /**
> >             *
> >             */
> >            private static final long serialVersionUID =
> > -6744838136235652577L;
> >
> >            protected void onUpdate(AjaxRequestTarget target) {
> >                System.out.println("Changed");
> >
> >            }
> >        });
> > .
> > .
> > .
> > .
> >
> > Quick Start here...
> > https://github.com/Sibgha360/dropdownexample.git,
>
>

Re: Notify Action to the Parent Class

Posted by Francois Meillet <fr...@gmail.com>.
Hi Sibgha,

// here is a simple code

//
// in your Dpanel
//
protected void onUpdate(AjaxRequestTarget target) {
    send(getPage(), Broadcast.EXACT, new YourEvent(yourDataFromYourDropDownChoice));
}


//
// in your HomePage, you override the onEvent method
//
@Override
public void onEvent(IEvent<?> event) {
    super.onEvent(event);

    if (event.getPayload() instanceof YourEvent) {
        
        YourEvent yourEvent = (YourEvent) = event.getPayload();
        // the data you sent throw your vent
        YourData xyz = yourEvent.getData();
        // if you don't neeed anymore your event
        event.stop();
    }
}


// look at the docs
https://ci.apache.org/projects/wicket/guide/8.x/single.html#_wicket_events_infrastructure


François
follow Apache Wicket on twitter : https://twitter.com/apache_wicket <https://twitter.com/apache_wicket> !


> Le 26 mai 2019 à 15:33, Sibgha Nazir <si...@gmail.com> a écrit :
> 
> Hi,
> 
> In my application, Home Page creates DPanel and Dpanel has the drop down
> menu.   In the class DPanel at 'onchange' event, I want to do some action
> in the class HomePage.java. How can that be possible?
> 
> 
> *HomePage.java*    public HomePage(final PageParameters parameters)
>    {
>        super(parameters);
> 
>        final Panel dropDownPanel = new Dpanel("toReplace");
> 
>        dropDownPanel.setOutputMarkupId(true);
>        add(dropDownPanel);
>    }
> 
> 
> *DPanel.java*    public Dpanel(String aId)
>    {
>        super(aId);
>        form = new Form<Void>("form");
>        form.setOutputMarkupId(true);
> 
>        // SelectMenu //
>        final DropDownChoice<String> dropdown = new
> DropDownChoice<String>("select", new Model<String>(), new
> ListModel<String>(GENRES));
>        dropdown.setRequired(true);
>        dropdown.setOutputMarkupId(true);
>        dropdown.add(new AjaxFormComponentUpdatingBehavior("change") {
>            /**
>             *
>             */
>            private static final long serialVersionUID =
> -6744838136235652577L;
> 
>            protected void onUpdate(AjaxRequestTarget target) {
>                System.out.println("Changed");
> 
>            }
>        });
> .
> .
> .
> .
> 
> Quick Start here...
> https://github.com/Sibgha360/dropdownexample.git,