我有两个用户:user&管理员。当用户添加新记录时,如果管理员已登录,我想在管理员界面中显示咆哮消息。
有可能吗?如果是这样,我怎么能做到这一点? JMS是否可能成为解决方案?
答案 0 :(得分:1)
您可以将私人聊天组件修改为您的案例
http://www.primefaces.org/showcase-labs/push/chat.jsf
一旦有人登录您的系统。您将用户注册到系统。
public void login() {
RequestContext requestContext = RequestContext.getCurrentInstance();
if(users.contains(username)) {
loggedIn = false;
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Username taken", "Try with another username."));
requestContext.update("growl");
}
else {
users.addUser(username);
pushContext.push(CHANNEL, username + " joined the channel.");
requestContext.execute("subscriber.connect('/" + username + "')");
loggedIn = true;
}
}
您可以通过发送推送通知向个人客户发送消息。
public void sendPrivate() {
pushContext.push(CHANNEL + privateUser, "[PM] " + username + ": " + privateMessage);
privateMessage = null;
}
然后处理即将发出的消息
<p:socket onMessage="handleMessage" channel="/chat" autoConnect="false" widgetVar="subscriber"/>
<script type="text/javascript">
function handleMessage(data) {
var chatContent = $(PrimeFaces.escapeClientId('form:public'));
chatContent.append(data + '<br />');
//keep scroll
chatContent.scrollTop(chatContent.height());
}
</script>