}
});
add(new EmoticonsBehavior("#" + MESSAGE_AREA_ID));
add(new WebMarkupContainer("messages").setMarkupId(MESSAGE_AREA_ID));
ChatToolbar toolbar = new ChatToolbar("toolbarContainer");
final WysiwygEditor chatMessage = new WysiwygEditor("chatMessage", Model.of(""), toolbar);
add(new Form<Void>("sendForm").add(
toolbar
, chatMessage.setOutputMarkupId(true)
, new AjaxButton("send") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
ChatDao dao = getBean(ChatDao.class);
ChatMessage m = new ChatMessage();
m.setMessage(unescapeXml(chatMessage.getDefaultModelObjectAsString()));
m.setSent(new Date());
m.setFromUser(getBean(UserDao.class).get(getUserId()));
dao.update(m);
IWebSocketConnectionRegistry reg = IWebSocketSettings.Holder.get(getApplication()).getConnectionRegistry();
for (IWebSocketConnection c : reg.getConnections(getApplication())) {
try {
c.sendMessage(getMessage(m).toString());
} catch(Exception e) {
log.error("Error while sending message", e);
}
}
chatMessage.setDefaultModelObject("");
target.add(chatMessage);
};
}));
}