Re: Notify Action to the Parent Class

2019-05-26 Thread Sebastien
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  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.meil...@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  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("form");
> > >form.setOutputMarkupId(true);
> > >
> > >// SelectMenu //
> > >final DropDownChoice dropdown = new
> > > DropDownChoice("select", new Model(), new
> > > ListModel(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

2019-05-26 Thread Sibgha Nazir
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 
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  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("form");
> >form.setOutputMarkupId(true);
> >
> >// SelectMenu //
> >final DropDownChoice dropdown = new
> > DropDownChoice("select", new Model(), new
> > ListModel(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

2019-05-26 Thread Francois Meillet
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 
 !


> Le 26 mai 2019 à 15:33, Sibgha Nazir  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("form");
>form.setOutputMarkupId(true);
> 
>// SelectMenu //
>final DropDownChoice dropdown = new
> DropDownChoice("select", new Model(), new
> ListModel(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,



Notify Action to the Parent Class

2019-05-26 Thread Sibgha Nazir
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("form");
form.setOutputMarkupId(true);

// SelectMenu //
final DropDownChoice dropdown = new
DropDownChoice("select", new Model(), new
ListModel(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,