0
我有兩個用戶:用戶& admin。當用戶添加新記錄時,如果管理員登錄,我想在管理員屏幕中顯示咆哮消息。PrimeFaces來自其他用戶事件的咆哮消息
可能嗎?如果是這樣,我該如何做到這一點? JMS是一種可能的解決方案嗎?
我有兩個用戶:用戶& admin。當用戶添加新記錄時,如果管理員登錄,我想在管理員屏幕中顯示咆哮消息。PrimeFaces來自其他用戶事件的咆哮消息
可能嗎?如果是這樣,我該如何做到這一點? JMS是一種可能的解決方案嗎?
您可以修改私人聊天組件到你的情況
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>
通信之間的用戶可以使用按鍵來完成http://www.primefaces.org/showcase-labs/push/index.jsf – Daniel