You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeffrey Schneller <je...@envisa.com> on 2012/03/28 20:33:24 UTC

Event handling and swapping panels

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);


Re: Event handling and swapping panels

Posted by Igor Vaynberg <ig...@gmail.com>.
yes, every panel has to have onevent. in this case the panel that has
onevent is replaced by a panel that doesnt, so it no longer receives
the event. what you should do is put the onevent in the page, not in
the panel.

-igor

On Wed, Mar 28, 2012 at 1:35 PM, Jeffrey Schneller
<je...@envisa.com> wrote:
> 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:igor.vaynberg@gmail.com]
> Sent: Wednesday, March 28, 2012 3:49 PM
> To: users@wicket.apache.org
> Subject: Re: Event handling and swapping panels
>
> that is correct
>
> -igor
>
> On Wed, Mar 28, 2012 at 12:41 PM, Jeffrey Schneller <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>> Sent: Wednesday, March 28, 2012 3:29 PM
>> To: users@wicket.apache.org
>> 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 <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>>> Sent: Wednesday, March 28, 2012 3:07 PM
>>> To: users@wicket.apache.org
>>> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


RE: Event handling and swapping panels

Posted by Jeffrey Schneller <je...@envisa.com>.
Thank you Igor and Francois!!  This solved my problem and it is working perfectly now.



-----Original Message-----
From: Francois Meillet [mailto:qqzzzzzzzz418@gmail.com] 
Sent: Wednesday, March 28, 2012 4:45 PM
To: users@wicket.apache.org
Subject: Re: Event handling and swapping panels

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:igor.vaynberg@gmail.com]
> Sent: Wednesday, March 28, 2012 3:49 PM
> To: users@wicket.apache.org
> Subject: Re: Event handling and swapping panels
> 
> that is correct
> 
> -igor
> 
> On Wed, Mar 28, 2012 at 12:41 PM, Jeffrey Schneller <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>> Sent: Wednesday, March 28, 2012 3:29 PM
>> To: users@wicket.apache.org
>> 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 <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>>> Sent: Wednesday, March 28, 2012 3:07 PM
>>> To: users@wicket.apache.org
>>> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ______________________________________________        
> This email has been scanned by Netintelligence        
> http://www.netintelligence.com/email
> 


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


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


Re: Event handling and swapping panels

Posted by Francois Meillet <qq...@gmail.com>.
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:igor.vaynberg@gmail.com] 
> Sent: Wednesday, March 28, 2012 3:49 PM
> To: users@wicket.apache.org
> Subject: Re: Event handling and swapping panels
> 
> that is correct
> 
> -igor
> 
> On Wed, Mar 28, 2012 at 12:41 PM, Jeffrey Schneller <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>> Sent: Wednesday, March 28, 2012 3:29 PM
>> To: users@wicket.apache.org
>> 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 <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>>> Sent: Wednesday, March 28, 2012 3:07 PM
>>> To: users@wicket.apache.org
>>> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> ______________________________________________        
> This email has been scanned by Netintelligence        
> http://www.netintelligence.com/email
> 


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


RE: Event handling and swapping panels

Posted by Jeffrey Schneller <je...@envisa.com>.
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:igor.vaynberg@gmail.com] 
Sent: Wednesday, March 28, 2012 3:49 PM
To: users@wicket.apache.org
Subject: Re: Event handling and swapping panels

that is correct

-igor

On Wed, Mar 28, 2012 at 12:41 PM, Jeffrey Schneller <je...@envisa.com> 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:igor.vaynberg@gmail.com]
> Sent: Wednesday, March 28, 2012 3:29 PM
> To: users@wicket.apache.org
> 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 <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>> Sent: Wednesday, March 28, 2012 3:07 PM
>> To: users@wicket.apache.org
>> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


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


Re: Event handling and swapping panels

Posted by Igor Vaynberg <ig...@gmail.com>.
that is correct

-igor

On Wed, Mar 28, 2012 at 12:41 PM, Jeffrey Schneller
<je...@envisa.com> 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:igor.vaynberg@gmail.com]
> Sent: Wednesday, March 28, 2012 3:29 PM
> To: users@wicket.apache.org
> 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 <je...@envisa.com> 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:igor.vaynberg@gmail.com]
>> Sent: Wednesday, March 28, 2012 3:07 PM
>> To: users@wicket.apache.org
>> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


RE: Event handling and swapping panels

Posted by Jeffrey Schneller <je...@envisa.com>.
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:igor.vaynberg@gmail.com] 
Sent: Wednesday, March 28, 2012 3:29 PM
To: users@wicket.apache.org
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 <je...@envisa.com> 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:igor.vaynberg@gmail.com]
> Sent: Wednesday, March 28, 2012 3:07 PM
> To: users@wicket.apache.org
> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


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


Re: Event handling and swapping panels

Posted by Igor Vaynberg <ig...@gmail.com>.
paste your entire panel/page class...

-igor

On Wed, Mar 28, 2012 at 12:15 PM, Jeffrey Schneller
<je...@envisa.com> 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:igor.vaynberg@gmail.com]
> Sent: Wednesday, March 28, 2012 3:07 PM
> To: users@wicket.apache.org
> 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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

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


RE: Event handling and swapping panels

Posted by Jeffrey Schneller <je...@envisa.com>.
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:igor.vaynberg@gmail.com] 
Sent: Wednesday, March 28, 2012 3:07 PM
To: users@wicket.apache.org
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 <je...@envisa.com> 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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Event handling and swapping panels

Posted by Igor Vaynberg <ig...@gmail.com>.
OuterPanelClass.this.panel.replaceWith(replacement);
OuterPanelClass.this.panel=replacement;

-igor

On Wed, Mar 28, 2012 at 11:33 AM, Jeffrey Schneller
<je...@envisa.com> 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);
>