I tried your advice and I keep the timer behavior "outside" the tab, in
MyTabbedPanel. In the refreshable panel  I register a listener with
MyApplication.get().addRefreshableComponent(Duration,Component). When I
select the tab with the refreshable panel all works fine but when I switch
the tab I received the same "PageExpiredException: No behavior listener
found with behaviorId".
Did I do something wrong or I misunderstood you?

Below is the java code:

public class MyTabbedPanel extends AjaxTabbedPanel {

        private static final long serialVersionUID = 1L;
        
        private List<AbstractAjaxTimerBehavior> ajaxTimerBehaviors;
                
        public ImageTabbedPanel(String id, List<ITab> tabs) {
                super(id, tabs);

                ajaxTimerBehaviors = new ArrayList<AbstractAjaxTimerBehavior>();
        }

        @Override
        protected WebMarkupContainer newLink(String linkId, final int index) {
                List<? extends ITab> tabs = getTabs();
                
                // check for usage of our custom class, if it is not our class, 
                // add as image empty container - this way you can use image 
only in tabs
you want
                ITab currentTab = tabs.get(index);
                if (currentTab instanceof ImageTab) {
                        final ImageTab imageTab = (ImageTab) currentTab;
                        return new ImageTabLink(linkId, imageTab.getImage()) {
                                
                                private static final long serialVersionUID = 1L;

                                @Override
                                public void onClick(AjaxRequestTarget target) {
                                        removeAjaxTimerBehaviors();
                                        clearRefreshableComponents();
                                        
                                        setSelectedTab(index);
                                        
                                        createAjaxTimerBehaviors();
                                        addAjaxTimerBehaviors();
                                        target.addComponent(MyTabbedPanel.this);
                                }
                                
                        };
                } else {
                        WebMarkupContainer link = super.newLink(linkId, index);
                        link.add(new 
WebMarkupContainer("image").setVisible(false));                    
                        
                        return link;
                }
        }
        
    private Map<Duration, List<Component>> getRefreshableComponents() {
        return MyApplication.get().getRefreshableComponents();
    }
    
    private void clearRefreshableComponents() {
        getRefreshableComponents().clear();
    }
    
        private void createAjaxTimerBehaviors() {
                final Map<Duration, List<Component>> refreshableComponents =
getRefreshableComponents();
                Set<Duration> durations = getRefreshableComponents().keySet();
                for (final Duration duration : durations) {
                        AbstractAjaxTimerBehavior behavior = new
AbstractAjaxTimerBehavior(duration) {

                                private static final long serialVersionUID = 1L;

                                @Override
                                protected void onTimer(AjaxRequestTarget 
target) {
                                        List<Component> components = 
refreshableComponents.get(duration);
                                        for (Component component : components) {
                                                target.addComponent(component);
                                        }
                                }
                                
                        };
                        ajaxTimerBehaviors.add(behavior);
                }
        }
        
        private void addAjaxTimerBehaviors() {
                for (IBehavior behavior : ajaxTimerBehaviors) {
                        add(behavior);
                }
        }
        
        private void removeAjaxTimerBehaviors() {
                for (AbstractAjaxTimerBehavior behavior : ajaxTimerBehaviors) {
                        behavior.stop();
                        remove(behavior);
                }
                
                ajaxTimerBehaviors.clear();
        }
        
}

-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/TabbedPanel-with-AjaxSelfUpdatingTimerBehavior-tp2243691p2247320.html
Sent from the Wicket - User mailing list archive at Nabble.com.

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

Reply via email to