user1433804
user1433804

Reputation: 657

PrimeFaces growl message from another user event

I have two users: user & admin. When the user adds a new record, I want to display a growl message in the admin screen if the admin is logged in.

Is it possible? If so, how can I achieve this? Is JMS a possible solution?

Upvotes: 0

Views: 1362

Answers (1)

erencan
erencan

Reputation: 3763

You can modify the private chat component into your case

http://www.primefaces.org/showcase-labs/push/chat.jsf

Once, anybody logs in to your system. you register user to the system.

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;  
        }  
    }

you can send message to individual client by sending push notifications.

public void sendPrivate() {  
        pushContext.push(CHANNEL + privateUser, "[PM] " + username + ": " + privateMessage);  

        privateMessage = null;  
    }  

Then handle the coming message

<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>

Upvotes: 1

Related Questions