Unless you override the onEvent method for each panel (MyPanel1, MyPanel2 and
MyPanel3) ,
only the first working panel will manage the event.
one solution would be :
public class Admin extends WebPage {
@Override
public void onEvent(IEvent<?> event) {
super.onEvent(event);
if (event.getPayload() instanceof MyPanelEvent) {
MyPanelEvent yourEvent = (MyPanelEvent) event.getPayload();
showSelectedPanel(yourEvent.getTarget(), yourEvent);
} else {
// your code here
}
}
private void showSelectedPanel(AjaxRequestTarget target, MyPanelEvent e) {
Component replacement;
switch (e.getType()) {
case PANEL1:
replacement = new MyPanel1("workingPanel");
//
break;
case PANEL2:
replacement = new MyPanel2("workingPanel");
break;
case PANEL3:
replacement = new MyPanel3("workingPanel");
break;
default:
replacement = Test333.this.workingPanel;
break;
}
Admin.this.workingPanel.replaceWith(replacement);
Admin.this.workingPanel = replacement;
replacement.setOutputMarkupId(true);
target.add(replacement);
target.appendJavaScript("alert('Panel changed to: " + e.getType() +
"');");
}
public void init() {
workingPanel = new PanelAAA("workingPanel");
workingPanel.setOutputMarkupId(true);
add(workingPanel);
AjaxLink p1Link = new AjaxLink("p1Link") {
@Override
public void onClick(AjaxRequestTarget target) {
log.debug("onClick");
send(getPage(), Broadcast.BREADTH, new YourEvent(target,
YourEvent.Type.PANEL1));
}
};
p1Link.setOutputMarkupId(true);
p1Link.setMarkupId("p1Link");
add(p1Link);
AjaxLink p2Link = new AjaxLink("p2Link") {
@Override
public void onClick(AjaxRequestTarget target) {
log.debug("onClick");
send(getPage(), Broadcast.BREADTH, new YourEvent(target,
YourEvent.Type.PANEL2));
}
};
p2Link.setOutputMarkupId(true);
p2Link.setMarkupId("p2Link");
add(p2Link);
AjaxLink p3Link = new AjaxLink("p3Link") {
@Override
public void onClick(AjaxRequestTarget target) {
log.debug("onClick");
send(getPage(), Broadcast.BREADTH, new YourEvent(target,
YourEvent.Type.PANEL3));
}
};
p3Link.setOutputMarkupId(true);
p3Link.setMarkupId("p3Link");
add(p3Link);
}
}
François
Le 28 mars 2012 à 22:35, Jeffrey Schneller a écrit :
> Only problem is that it is not working. The panels never update to the new
> panels. I can see that the onEvent fires as the javascript alert is shown.
> But the javascript is only shown the first time I click a link. After the
> first click, all the links call their onClick method and send the event out
> but the event is never picked up. Does every panel need to have its own
> onEvent method to listen for the events.
>
> If so, I think the old method of handling ajax is going to be easier.
>
>
> -----Original Message-----
> From: Igor Vaynberg [mailto:[email protected]]
> Sent: Wednesday, March 28, 2012 3:49 PM
> To: [email protected]
> Subject: Re: Event handling and swapping panels
>
> that is correct
>
> -igor
>
> On Wed, Mar 28, 2012 at 12:41 PM, Jeffrey Schneller
> <[email protected]> wrote:
>> Here it is:
>>
>>
>> public class Admin extends WebPage {
>>
>> private Component workingPanel;
>>
>> public Admin() {
>> super();
>> init();
>> }
>>
>> @Override
>> public void renderHead(IHeaderResponse response) {
>> response.renderCSSReference("css/admin.css");
>> super.renderHead(response);
>> }
>>
>> public void init() {
>> workingPanel = new MyEmptyPanel("workingPanel") {
>> @Override
>> public void onEvent(IEvent<?> event) {
>> if (event.getPayload() instanceof
>> MyPanelEvent) {
>> MyPanelEvent e = (MyPanelEvent)
>> event.getPayload();
>> AjaxRequestTarget target =
>> e.getTarget();
>>
>> Component replacement;
>> switch (e.getType()) {
>> case MyPanelEvent.PANEL1:
>> replacement = new
>> MyPanel1(this.getId());
>> break;
>> case MyPanelEvent.PANEL2:
>> replacement = new
>> MyPanel2(this.getId());
>> break;
>> case MyPanelEvent.PANEL3:
>> replacement = new
>> MyPanel3(this.getId());
>> break;
>> default:
>> replacement =
>> Admin.this.workingPanel;
>> break;
>> }
>>
>>
>> Admin.this.workingPanel.replaceWith(replacement); // IS THIS RIGHT?
>> Admin.this.workingPanel =
>> replacement; // IS THIS RIGHT?
>> this.setOutputMarkupId(true);
>> target.add(this);
>>
>> target.appendJavaScript("alert('Panel changed to: " + e.getType() +
>> "');"); // place-holder for future javascript to be called
>> }
>> super.onEvent(event);
>> }
>> };
>> workingPanel.setOutputMarkupId(true);
>> add(workingPanel);
>>
>> AjaxLink p1Link = new AjaxLink("p1Link") {
>> @Override
>> public void onClick(AjaxRequestTarget target) {
>> send(getPage(), Broadcast.BREADTH, new
>> MyPanelEvent(target, MyPanelEvent.PANEL1));
>> }
>> };
>> p1Link.setOutputMarkupId(true);
>> p1Link.setMarkupId("p1Link");
>> add(p1Link);
>>
>> AjaxLink p2Link = new AjaxLink("p2Link") {
>> @Override
>> public void onClick(AjaxRequestTarget target) {
>> send(getPage(), Broadcast.BREADTH, new
>> MyPanelEvent(target, MyPanelEvent.PANEL2));
>> }
>> };
>> p2Link.setOutputMarkupId(true);
>> p2Link.setMarkupId("p2Link");
>> add(p2Link);
>>
>> AjaxLink p3Link = new AjaxLink("p3Link") {
>> @Override
>> public void onClick(AjaxRequestTarget target) {
>> send(getPage(), Broadcast.BREADTH, new
>> MyPanelEvent(target, MyPanelEvent.PANEL3));
>> }
>> };
>> p3Link.setOutputMarkupId(true);
>> p3Link.setMarkupId("p3Link");
>> add(p3Link);
>> }
>> }
>>
>> -----Original Message-----
>> From: Igor Vaynberg [mailto:[email protected]]
>> Sent: Wednesday, March 28, 2012 3:29 PM
>> To: [email protected]
>> Subject: Re: Event handling and swapping panels
>>
>> paste your entire panel/page class...
>>
>> -igor
>>
>> On Wed, Mar 28, 2012 at 12:15 PM, Jeffrey Schneller
>> <[email protected]> wrote:
>>> Thanks. But what does OuterPanelClass refer to in my example?
>>>
>>> I don't think either of these are right:
>>>
>>> MyEmptyPanel.this.panel.replaceWith(replacement);
>>> -or-
>>> MyPage.this.panel.replaceWith(replacement);
>>>
>>> Or do I need to define workingPanel as a private member of my page class
>>> and then have:
>>>
>>> MyPage.this.workingPanel.replaceWith(replacement);
>>> MyPage.this.workingPanel = replacement;
>>>
>>>
>>>
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: Igor Vaynberg [mailto:[email protected]]
>>> Sent: Wednesday, March 28, 2012 3:07 PM
>>> To: [email protected]
>>> Subject: Re: Event handling and swapping panels
>>>
>>> OuterPanelClass.this.panel.replaceWith(replacement);
>>> OuterPanelClass.this.panel=replacement;
>>>
>>> -igor
>>>
>>> On Wed, Mar 28, 2012 at 11:33 AM, Jeffrey Schneller
>>> <[email protected]> wrote:
>>>> I want to swap panels using the event model in 1.5. This is very similar
>>>> to the panel swapping code (wicket 1.4.x) found in the Apache Wicket
>>>> Cookbook but uses the event model instead. The problem is I can't set the
>>>> panel equal to its replacement, like you would in 1.4.x. This is found on
>>>> the line marked ***** THIS IS NOT POSSIBLE *****.
>>>>
>>>> How would you go about doing this? Is it even possible?
>>>>
>>>> Component workingPanel = new MyEmptyPanel("workingPanel") {
>>>> @Override
>>>> public void onEvent(IEvent<?> event) {
>>>> if
>>>> (event.getPayload() instanceof MyPanelEvent) {
>>>>
>>>> MyPanelEvent e = (MyPanelEvent) event.getPayload();
>>>>
>>>> Component
>>>> replacement;
>>>>
>>>> switch
>>>> (e.getType()) {
>>>>
>>>> case
>>>> MyPanelEvent.PANEL1:
>>>>
>>>> replacement = new MyFirstPanel(this.getId());
>>>>
>>>> break;
>>>> default:
>>>>
>>>> replacement = this;
>>>>
>>>> break;
>>>> }
>>>>
>>>> this.replaceWith(replacement);
>>>> this. = replacement;
>>>> // ****** THIS IS NOT POSSIBLE - HOW WOULD I DO THIS *******
>>>>
>>>> this.setOutputMarkupId(true);
>>>> AjaxRequestTarget
>>>> target = e.getTarget();
>>>> target.add(this);
>>>> }
>>>> super.onEvent(event);
>>>> }
>>>> workingPanel.setOutputMarkupId(true);
>>>> add(workingPanel);
>>>>
>>>> AjaxLink firsttab = new AjaxLink("firsttab") {
>>>> @Override
>>>> public void onClick(AjaxRequestTarget target) {
>>>> send(getPage(), Broadcast.BREADTH,
>>>> new MyPanelEvent (target, MyPanelEvent.PANEL1));
>>>> }
>>>> };
>>>> firsttab.setOutputMarkupId(true);
>>>> firsttab.setMarkupId("firsttab ");
>>>> add(firsttab);
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [email protected]
>>> For additional commands, e-mail: [email protected]
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
> ______________________________________________
> This email has been scanned by Netintelligence
> http://www.netintelligence.com/email
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]