/** * As {@link #withPageFiltered}, but for use when there is more than one copy of DWR * in a ServletContext. * <p> * For 99% of cases the former method will be much simpler to use. * @param serverContext The specific DWR context in which to execute */ public static void withPageFiltered(ServerContext serverContext, String page, ScriptSessionFilter filter, Runnable task) { currentServerContext.set(serverContext); try { ScriptSessionFilter pageFilter = new PageScriptSessionFilter(serverContext, page); ScriptSessionFilter realFilter = new AndScriptSessionFilter(pageFilter, filter); TaskDispatcher taskDispatcher = TaskDispatcherFactory.get(serverContext); taskDispatcher.dispatchTask(realFilter, task); } finally { currentServerContext.remove(); } }
/** * Execute a task and aim the output at a subset of the browser windows open * at the same page as the current request. The filter allows you to select * the set of users that will be interested in the update. * This implies that this method is only of use from a DWR created thread. * @param filter Used to define the set of browser windows which should * receive the update. * @param task A code block to execute */ public static void withCurrentPageFiltered(ScriptSessionFilter filter, Runnable task) { WebContext webContext = WebContextFactory.get(); String page = webContext.getCurrentPage(); ScriptSessionFilter pageFilter = new PageScriptSessionFilter(webContext, page); ScriptSessionFilter realFilter = new AndScriptSessionFilter(pageFilter, filter); TaskDispatcher taskDispatcher = TaskDispatcherFactory.get(webContext); taskDispatcher.dispatchTask(realFilter, task); }