Example usage for org.apache.wicket.protocol.ws.api WebSocketBehavior WebSocketBehavior

List of usage examples for org.apache.wicket.protocol.ws.api WebSocketBehavior WebSocketBehavior

Introduction

In this page you can find the example usage for org.apache.wicket.protocol.ws.api WebSocketBehavior WebSocketBehavior.

Prototype

public WebSocketBehavior() 

Source Link

Usage

From source file:com.googlecode.wicket.jquery.ui.plugins.whiteboard.Whiteboard.java

License:Apache License

/**
 * Creating a whiteboard instance for given element id
 * @param id// ww w  .j a  va  2s.c om
 */
public Whiteboard(String id, String whiteboardContent) {
    super(id);

    //Adding Web Socket behaviour to handle synchronization between whiteboards

    this.add(new WebSocketBehavior() {
        private static final long serialVersionUID = -3311970325911992958L;

        @Override
        protected void onConnect(ConnectedMessage message) {
            super.onConnect(message);
            log.debug("Connecting :" + message.toString());
        }

        @Override
        protected void onClose(ClosedMessage message) {
            super.onClose(message);
            log.debug("Disconnecting :" + message.toString());
        }
    });

    WebMarkupContainer whiteboard = new WebMarkupContainer("whiteboard");
    this.add(whiteboard);

    WhiteboardBehavior whiteboardBehavior = new WhiteboardBehavior("whiteboard", whiteboardContent);
    this.add(whiteboardBehavior);
}

From source file:com.wicketinaction.WebSocketBehaviorDemoPage.java

License:Apache License

public WebSocketBehaviorDemoPage() {
    WebSocketChart chartPanel = new WebSocketChart("chartPanel");
    chartPanel.add(new WebSocketBehavior() {
        @Override//from   w  ww.  j  av  a 2  s  . co m
        protected void onConnect(ConnectedMessage message) {
            super.onConnect(message);

            ChartUpdater.start(message);
        }
    });
    add(chartPanel);
}

From source file:org.apache.openmeetings.web.common.MainPanel.java

License:Apache License

public MainPanel(String id, WebMarkupContainer panel) {
    super(id);//from w  w  w . jav a 2  s  .co m
    client = new Client();
    add(topControls.setOutputMarkupPlaceholderTag(true).setMarkupId("topControls"));
    menu = new MenuPanel("menu", getMainMenu());
    contents = new WebMarkupContainer("contents");
    add(contents.add(panel).setOutputMarkupId(true).setMarkupId("contents"));
    topControls.add(menu.setVisible(false),
            topLinks.setVisible(false).setOutputMarkupPlaceholderTag(true).setMarkupId("topLinks"));
    topLinks.add(new AjaxLink<Void>("messages") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            updateContents(PROFILE_MESSAGES, target);
        }
    });
    topLinks.add(new ConfirmableAjaxBorder("logout", getString("310"), getString("634")) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            getSession().invalidate();
            setResponsePage(Application.get().getSignInPageClass());
        }
    });
    topLinks.add(new AjaxLink<Void>("profile") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            updateContents(PROFILE_EDIT, target);
        }
    });
    final AboutDialog about = new AboutDialog("aboutDialog");
    topLinks.add(new AjaxLink<Void>("about") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            about.open(target);
        }
    });
    if (getApplication().getDebugSettings().isDevelopmentUtilitiesEnabled()) {
        add(new DebugBar("dev").setOutputMarkupId(true));
    } else {
        add(new EmptyPanel("dev").setVisible(false));
    }
    add(about, chat = new ChatPanel("chatPanel"));
    add(newMessage = new MessageDialog("newMessageDialog",
            new CompoundPropertyModel<PrivateMessage>(new PrivateMessage())) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClose(IPartialPageRequestHandler handler, DialogButton button) {
            BasePanel bp = getCurrentPanel();
            if (send.equals(button) && bp != null) {
                bp.onNewMessageClose(handler);
            }
        }
    });
    add(userInfo = new UserInfoDialog("userInfoDialog", newMessage));
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            userInfo.open(target, getParam(getComponent(), PARAM_USER_ID).toLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript(
                    getNamedFunction("showUserInfo", this, explicit(PARAM_USER_ID)), "showUserInfo")));
        }
    });
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            ContactsHelper.addUserToContactList(getParam(getComponent(), PARAM_USER_ID).toLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(JavaScriptHeaderItem
                    .forScript(getNamedFunction("addContact", this, explicit(PARAM_USER_ID)), "addContact")));
        }
    });
    add(new AbstractDefaultAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {
            newMessage.reset(true).open(target, getParam(getComponent(), PARAM_USER_ID).toOptionalLong());
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {
            super.renderHead(component, response);
            response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forScript(
                    getNamedFunction("privateMessage", this, explicit(PARAM_USER_ID)), "privateMessage")));
        }
    });
    add(new WebSocketBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onConnect(ConnectedMessage message) {
            super.onConnect(message);
            addOnlineUser(new Client(message.getSessionId(), message.getKey(), getUserId()));
            log.debug(String.format("WebSocketBehavior::onConnect [session: %s, key: %s]",
                    message.getSessionId(), message.getKey()));
        }

        @Override
        protected void onClose(ClosedMessage message) {
            Client client = getClientByKeys(getUserId(), WebSession.get().getId());
            removeOnlineUser(client);
            super.onClose(message);
            log.debug("WebSocketBehavior::onClose");
        }
    });
}

From source file:org.apache.syncope.client.console.pages.BasePage.java

License:Apache License

public BasePage(final PageParameters parameters) {
    super(parameters);

    // Native WebSocket
    add(new WebSocketBehavior() {

        private static final long serialVersionUID = 3109256773218160485L;

        @Override/*  w w w.  j  a v a  2 s . com*/
        protected void onConnect(final ConnectedMessage message) {
            super.onConnect(message);

            SyncopeConsoleSession.get().scheduleAtFixedRate(new ApprovalsWidget.ApprovalInfoUpdater(message), 0,
                    30, TimeUnit.SECONDS);

            if (BasePage.this instanceof Dashboard) {
                SyncopeConsoleSession.get().scheduleAtFixedRate(new JobWidget.JobInfoUpdater(message), 0, 10,
                        TimeUnit.SECONDS);
                SyncopeConsoleSession.get().scheduleAtFixedRate(
                        new ReconciliationWidget.ReconciliationJobInfoUpdater(message), 0, 10,
                        TimeUnit.SECONDS);
            }
        }

    });

    body = new WebMarkupContainer("body");
    Serializable leftMenuCollapse = SyncopeConsoleSession.get()
            .getAttribute(SyncopeConsoleSession.MENU_COLLAPSE);
    if ((leftMenuCollapse instanceof Boolean) && ((Boolean) leftMenuCollapse)) {
        body.add(new AttributeAppender("class", " sidebar-collapse"));
    }
    add(body);

    notificationPanel = new NotificationPanel(Constants.FEEDBACK);
    body.addOrReplace(notificationPanel.setOutputMarkupId(true));

    // header, footer
    body.add(new Label("version", SyncopeConsoleApplication.get().getVersion()));
    body.add(new Label("username", SyncopeConsoleSession.get().getSelfTO().getUsername()));

    body.add(new ApprovalsWidget("approvalsWidget", getPageReference()).setRenderBodyOnly(true));

    // right sidebar
    SystemInfo systemInfo = SyncopeConsoleSession.get().getSystemInfo();
    body.add(new Label("hostname", systemInfo.getHostname()));
    body.add(new Label("processors", systemInfo.getAvailableProcessors()));
    body.add(new Label("os", systemInfo.getOs()));
    body.add(new Label("jvm", systemInfo.getJvm()));

    Link<Void> dbExportLink = new Link<Void>("dbExportLink") {

        private static final long serialVersionUID = -4331619903296515985L;

        @Override
        public void onClick() {
            try {
                HttpResourceStream stream = new HttpResourceStream(new ConfigurationRestClient().dbExport());

                ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
                rsrh.setFileName(
                        stream.getFilename() == null ? SyncopeConsoleSession.get().getDomain() + "Content.xml"
                                : stream.getFilename());
                rsrh.setContentDisposition(ContentDisposition.ATTACHMENT);

                getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh);
            } catch (Exception e) {
                SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
            }
        }
    };
    MetaDataRoleAuthorizationStrategy.authorize(dbExportLink, WebPage.ENABLE,
            StandardEntitlement.CONFIGURATION_EXPORT);
    body.add(dbExportLink);

    // menu
    WebMarkupContainer liContainer = new WebMarkupContainer(getLIContainerId("dashboard"));
    body.add(liContainer);
    liContainer.add(BookmarkablePageLinkBuilder.build("dashboard", Dashboard.class));

    liContainer = new WebMarkupContainer(getLIContainerId("realms"));
    body.add(liContainer);
    BookmarkablePageLink<? extends BasePage> link = BookmarkablePageLinkBuilder.build("realms", Realms.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.REALM_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("topology"));
    body.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("topology", Topology.class);
    StringBuilder bld = new StringBuilder();
    bld.append(StandardEntitlement.CONNECTOR_LIST).append(",").append(StandardEntitlement.RESOURCE_LIST)
            .append(",");
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, bld.toString());
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("reports"));
    body.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("reports", Reports.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.REPORT_LIST);
    liContainer.add(link);

    WebMarkupContainer confLIContainer = new WebMarkupContainer(getLIContainerId("configuration"));
    body.add(confLIContainer);
    WebMarkupContainer confULContainer = new WebMarkupContainer(getULContainerId("configuration"));
    confLIContainer.add(confULContainer);

    liContainer = new WebMarkupContainer(getLIContainerId("workflow"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("workflow", Workflow.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.WORKFLOW_DEF_READ);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("audit"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("audit", Audit.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.AUDIT_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("logs"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("logs", Logs.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.LOG_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("securityquestions"));
    confULContainer.add(liContainer);
    bld = new StringBuilder();
    bld.append(StandardEntitlement.SECURITY_QUESTION_CREATE).append(",")
            .append(StandardEntitlement.SECURITY_QUESTION_DELETE).append(",")
            .append(StandardEntitlement.SECURITY_QUESTION_UPDATE);
    link = BookmarkablePageLinkBuilder.build("securityquestions", SecurityQuestions.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, bld.toString());
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("types"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("types", Types.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.SCHEMA_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("roles"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("roles", Roles.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.ROLE_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("policies"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("policies", Policies.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.POLICY_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("notifications"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("notifications", Notifications.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.NOTIFICATION_LIST);
    liContainer.add(link);

    liContainer = new WebMarkupContainer(getLIContainerId("parameters"));
    confULContainer.add(liContainer);
    link = BookmarkablePageLinkBuilder.build("parameters", Parameters.class);
    MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, StandardEntitlement.CONFIGURATION_LIST);
    liContainer.add(link);

    body.add(new AjaxLink<Void>("collapse") {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            SyncopeConsoleSession.get().setAttribute(SyncopeConsoleSession.MENU_COLLAPSE,
                    SyncopeConsoleSession.get().getAttribute(SyncopeConsoleSession.MENU_COLLAPSE) == null ? true
                            : !(Boolean) SyncopeConsoleSession.get()
                                    .getAttribute(SyncopeConsoleSession.MENU_COLLAPSE));
        }
    });
    body.add(new Label("domain", SyncopeConsoleSession.get().getDomain()));
    body.add(new BookmarkablePageLink<Page>("logout", Logout.class));

    // set 'active' menu item for everything but extensions
    // 1. check if current class is set to top-level menu
    Component containingLI = body.get(getLIContainerId(getClass().getSimpleName().toLowerCase()));
    // 2. if not, check if it is under 'Configuration'
    if (containingLI == null) {
        containingLI = confULContainer.get(getLIContainerId(getClass().getSimpleName().toLowerCase()));
    }
    // 3. when found, set CSS coordinates for menu
    if (containingLI != null) {
        containingLI.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {
                tag.put("class", "active");
            }
        });

        if (confULContainer.getId().equals(containingLI.getParent().getId())) {
            confULContainer.add(new Behavior() {

                private static final long serialVersionUID = 3109256773218160485L;

                @Override
                public void onComponentTag(final Component component, final ComponentTag tag) {
                    tag.put("class", "treeview-menu menu-open");
                    tag.put("style", "display: block;");
                }

            });

            confLIContainer.add(new Behavior() {

                private static final long serialVersionUID = 3109256773218160485L;

                @Override
                public void onComponentTag(final Component component, final ComponentTag tag) {
                    tag.put("class", "treeview active");
                }
            });
        }
    }

    // Extensions
    ClassPathScanImplementationLookup classPathScanImplementationLookup = (ClassPathScanImplementationLookup) SyncopeConsoleApplication
            .get().getServletContext().getAttribute(ConsoleInitializer.CLASSPATH_LOOKUP);
    List<Class<? extends BaseExtPage>> extPageClasses = classPathScanImplementationLookup.getExtPageClasses();

    WebMarkupContainer extensionsLI = new WebMarkupContainer(getLIContainerId("extensions"));
    extensionsLI.setOutputMarkupPlaceholderTag(true);
    extensionsLI.setVisible(!extPageClasses.isEmpty());
    body.add(extensionsLI);

    ListView<Class<? extends BaseExtPage>> extPages = new ListView<Class<? extends BaseExtPage>>("extPages",
            extPageClasses) {

        private static final long serialVersionUID = 4949588177564901031L;

        @Override
        protected void populateItem(final ListItem<Class<? extends BaseExtPage>> item) {
            WebMarkupContainer containingLI = new WebMarkupContainer("extPageLI");
            item.add(containingLI);
            if (item.getModelObject().equals(BasePage.this.getClass())) {
                containingLI.add(new Behavior() {

                    private static final long serialVersionUID = 1469628524240283489L;

                    @Override
                    public void onComponentTag(final Component component, final ComponentTag tag) {
                        tag.put("class", "active");
                    }
                });
            }

            ExtPage ann = item.getModelObject().getAnnotation(ExtPage.class);

            BookmarkablePageLink<Page> link = new BookmarkablePageLink<>("extPage", item.getModelObject());
            link.add(new Label("extPageLabel", ann.label()));
            MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.ENABLE, ann.listEntitlement());
            containingLI.add(link);

            Label extPageIcon = new Label("extPageIcon");
            extPageIcon.add(new AttributeModifier("class", "fa " + ann.icon()));
            link.add(extPageIcon);
        }
    };
    extPages.setOutputMarkupId(true);
    extensionsLI.add(extPages);

    if (getPage() instanceof BaseExtPage) {
        extPages.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {
                tag.put("class", "treeview-menu menu-open");
                tag.put("style", "display: block;");
            }

        });

        extensionsLI.add(new Behavior() {

            private static final long serialVersionUID = 1469628524240283489L;

            @Override
            public void onComponentTag(final Component component, final ComponentTag tag) {
                tag.put("class", "treeview active");
            }
        });
    }
}

From source file:org.efaps.ui.wicket.pages.main.MainPage.java

License:Apache License

/**
 * Constructor adding all Components to this Page.
 * @throws CacheReloadException on error
 *///from w  w  w  . ja v a 2  s  .co  m
public MainPage() throws CacheReloadException {
    super();
    // add the debug bar for administration role, in case of an erro only log it
    Component debug = null;
    try {
        // Administration
        final Role role = Role.get(KernelSettings.USER_ROLE_ADMINISTRATION);
        if (role != null && Context.getThreadContext().getPerson().isAssigned(role)) {
            debug = new DebugBar("debug");
        }
    } catch (final CacheReloadException e) {
        MainPage.LOG.error("Error on retrieving Role assignment.", e);
    } catch (final EFapsException e) {
        MainPage.LOG.error("Error on retrieving Role assignment.", e);
    } finally {
        if (debug == null) {
            debug = new WebComponent("debug").setVisible(false);
        }
        add(debug);
    }

    // call the client info to force the reload script to be executed on the
    // beginning of a session,
    // if an ajax call would be done as first an error occurs
    ((WebClientInfo) Session.get().getClientInfo()).getProperties();

    add(new RequireBehavior("dojo/dom", "dojo/_base/window"));
    add(new PreLoaderPanel("preloader"));

    add(new OpenWindowOnLoadBehavior());

    final WebMarkupContainer borderPanel = new WebMarkupContainer("borderPanel");
    this.add(borderPanel);
    borderPanel.add(new BorderContainerBehavior(Design.HEADLINE, false));

    final LazyIframe mainPanel = new LazyIframe("mainPanel", new IFrameProvider() {

        private static final long serialVersionUID = 1L;

        @Override
        public Page getPage() {
            Page error = null;
            WebPage page = null;
            try {
                page = new DashboardPage(getPageReference());
            } catch (final EFapsException e) {
                error = new ErrorPage(e);
            }
            return error == null ? page : error;
        }
    }, MainPage.IFRAME_ID);

    borderPanel.add(mainPanel);
    mainPanel.add(new ContentPaneBehavior(Region.CENTER, false));

    final WebMarkupContainer headerPanel = new WebMarkupContainer("headerPanel");
    borderPanel.add(headerPanel);
    headerPanel.add(new ContentPaneBehavior(Region.TOP, false));

    headerPanel.add(new MenuBarPanel("menubar",
            Model.of(new UIMenuItem(UUID.fromString(Configuration.getAttribute(ConfigAttribute.TOOLBAR))))));

    // set the title for the Page
    add2Page(new Label("pageTitle", DBProperties.getProperty("Logo.Version.Label")));

    add(this.modal);
    add(new ResizeEventBehavior());

    try {
        // only add the search if it is activated in the kernel
        if (EFapsSystemConfiguration.get().getAttributeValueAsBoolean(KernelSettings.INDEXACTIVATE)) {
            final SearchPanel search = new SearchPanel("search");
            add(search);
        } else {
            add(new WebMarkupContainer("search").setVisible(false));
        }
    } catch (final EFapsException e1) {
        MainPage.LOG.error("Error on retrieving setting for index", e1);
    }

    final WebMarkupContainer logo = new WebMarkupContainer("logo");
    headerPanel.add(logo);

    final Label welcome = new Label("welcome", DBProperties.getProperty("Logo.Welcome.Label"));
    logo.add(welcome);

    try {
        final Context context = Context.getThreadContext();
        logo.add(new Label("firstname", context.getPerson().getFirstName()));
        logo.add(new Label("lastname", context.getPerson().getLastName()));
        final String companyName = context.getCompany() == null ? "" : context.getCompany().getName();
        logo.add(new Label("company", companyName));
        logo.add(new AttributeModifier("class", new Model<>("eFapsLogo " + companyName.replaceAll("\\W", ""))));
        final long usrId = context.getPersonId();
        // Admin_Common_SystemMessageAlert
        final LinkItem alert = new LinkItem("useralert",
                Model.of(new UIMenuItem(SetMessageStatusBehavior.getCmdUUD()))) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onComponentTagBody(final MarkupStream _markupStream, final ComponentTag _openTag) {
                try {
                    replaceComponentTagBody(_markupStream, _openTag,
                            SetMessageStatusBehavior.getLabel(MessageStatusHolder.getUnReadCount(usrId),
                                    MessageStatusHolder.getReadCount(usrId)));
                } catch (final CacheReloadException e) {
                    MainPage.LOG.error("Cannot replace Component tag");
                }
            }
        };
        add(alert);
        alert.add(new MessageListenerBehavior());
        alert.add(new AttributeModifier("class", new Model<>("eFapsUserMsg")));
        if (!MessageStatusHolder.hasReadMsg(usrId)) {
            alert.add(new AttributeModifier("style", new Model<>("display:none")));
        }
        final WebMarkupContainer socketMsgContainer = new WebMarkupContainer("socketMsgContainer");
        add(socketMsgContainer);
        if (Configuration.getAttributeAsBoolean(ConfigAttribute.WEBSOCKET_ACTVATE)) {
            socketMsgContainer.setOutputMarkupPlaceholderTag(true);
            this.socketMsg = new Label("socketMsg", "none yet").setEscapeModelStrings(false);
            this.socketMsg.setOutputMarkupPlaceholderTag(true);
            this.socketMsg.add(new WebSocketBehavior() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void onConnect(final ConnectedMessage _message) {
                    RegistryManager.addMsgConnection(_message.getSessionId(), _message.getKey());
                }
            });
            socketMsgContainer.add(this.socketMsg);

            final AjaxLink<Void> close = new AjaxLink<Void>("socketMsgClose") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(final AjaxRequestTarget _target) {
                    final MarkupContainer msgContainer = MainPage.this.socketMsg.getParent();
                    msgContainer.add(new AttributeModifier("style", new Model<>("display:none")));
                    _target.add(msgContainer);
                }
            };
            socketMsgContainer.add(close);
        } else {
            socketMsgContainer.setVisible(false);
        }
    } catch (final EFapsException e) {
        throw new RestartResponseException(new ErrorPage(e));
    }
}

From source file:org.wicketstuff.whiteboard.Whiteboard.java

License:Apache License

/**
 * This is the constructor which used to create a whiteboard in a wicket application
 * /*from  w  w w .  j a  v  a 2 s  . c o m*/
 * @param markupId
 *            html element markupId which holds the whiteboard
 * @param whiteboardContent
 *            If loading from a saved whiteboard file, content should be provided as a string. Otherwise null
 * @param clipArtFolderPath
 *            Path of the folder which holds clipArts which can be added to whiteboard. Relative to context root
 * @param docFolderPath
 *            Path of the folder which holds docs images which can be added to whiteboard. Relative to context root
 */
public Whiteboard(String whiteboardID, String markupId, String whiteboardContent, String clipArtFolderPath,
        String docFolderPath) {
    super(markupId);

    // Adding Web Socket behaviour to handle synchronization between whiteboards

    this.add(new WebSocketBehavior() {
        private static final long serialVersionUID = -3311970325911992958L;

        @Override
        protected void onConnect(ConnectedMessage message) {
            super.onConnect(message);
            log.debug("Connecting :" + message.toString());
        }

        @Override
        protected void onClose(ClosedMessage message) {
            super.onClose(message);
            log.debug("Disconnecting :" + message.toString());
        }
    });

    add(new WebMarkupContainer("whiteboard"));
    add(new WhiteboardBehavior(whiteboardID, "whiteboard", whiteboardContent, clipArtFolderPath,
            docFolderPath));
}