Send a message only to one user

UI Components for JSF
Post Reply
magsam
Posts: 71
Joined: 18 Jun 2012, 17:43
Location: Bavaria, DE
Contact:

17 Feb 2015, 17:31

Hello,

I need more comfort for my chatusers. In my application I use chat and notify. I works fine. The users want a sign when somebody wants to chat with them, like in skype. The minimized chatdialog is in the taskbar.

The best sign would be a growl message. The PushContext is deprecated (pushContext.push(channels.getChannel(privateUser), new FacesMessage("Hello I want to chat with you",summary)); ) .

With : eventBus.publish(CHANNEL ,
new FacesMessage(StringEscapeUtils.escapeHtml(summary),
StringEscapeUtils.escapeHtml(privateMessage)));

I reach all subscribers and not the only one to whom I want to chat.

Does anyone know a solution?

Thanks and regards from

Peter
PrimeFaces 6.1, Extensions 6.1.1 , Mojarra 2.3 , GlassFish Server Open Source Edition 4.1 (build 13) , atmosphere-runtime 2.4.9 , Open Source ERP with Primefaces http://osretail.de/osRetail/

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

17 Feb 2015, 23:18

Create a specific channel per user. See the primefaces chat example where private 1 to 1 chatting is also possible

magsam
Posts: 71
Joined: 18 Jun 2012, 17:43
Location: Bavaria, DE
Contact:

18 Feb 2015, 12:34

Hello kukeltje,

I tried your solution without success. In the chat is we use no "new FacesMessage" . My "normal" chat works fine, I have no problems with it.

regards

Peter
PrimeFaces 6.1, Extensions 6.1.1 , Mojarra 2.3 , GlassFish Server Open Source Edition 4.1 (build 13) , atmosphere-runtime 2.4.9 , Open Source ERP with Primefaces http://osretail.de/osRetail/

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

19 Feb 2015, 11:15

Well, I took the chat example as a starting point and with some little modifications it did work.... So unless you post code, it is difficult to say where your problem is

magsam
Posts: 71
Joined: 18 Jun 2012, 17:43
Location: Bavaria, DE
Contact:

20 Feb 2015, 12:56

Hello Kukeltje,
here is my code for better understanding:

Code: Select all

@ManagedBean
@ViewScoped
public class ChatView {	

	@ManagedProperty("#{logon}")
	private Logon logon;
	private Usr usr;

	private final EventBus eventBus = EventBusFactory.getDefault().eventBus();
			 
	@ManagedProperty("de.osretail.basis.ChatUsers")
	private ChatUsers users = new ChatUsers();
 
	private String privateMessage;
	 
	private List<Usr> listeuser = null;
	private String username = null;
 
	private String user;
	private int listid;	
	private int first;
	private boolean loggedIn;
	private String privateUser;
 
 	private final static String CHANNEL = "/{room}/";
 	private final static String CHANNELA = "/{anfrage}";

	private String summary, detail;
	private boolean neu = false;
	
	public void nullsetzen() {		
		 first=0;			 	
	}

	public void sendPrivate() {		
		if(first==0){
			first=1;
			summary = "Guten Tag " +privateUser;	
			// only the selected user should get the message
	 	eventBus.publish(CHANNELA , 
	   				new FacesMessage(StringEscapeUtils.escapeHtml(summary),
	   						StringEscapeUtils.escapeHtml(privateMessage)));	
	 	
		eventBus.publish(CHANNEL + username, privateUser +": "
	  			+ StringEscapeUtils.escapeHtml(privateMessage));
		}else{	
			
  		eventBus.publish(CHANNEL + privateUser, username +  ": "
 				+ StringEscapeUtils.escapeHtml(privateMessage));
			 		
  	eventBus.publish(CHANNEL + username, username + ": "
  			+ StringEscapeUtils.escapeHtml(privateMessage));
		privateMessage = "";	
		}	
	}

	public void login() {
		RequestContext context = RequestContext.getCurrentInstance();
		users.add(username);
		context.execute("PF('subscriber').connect('/" + username + "')");
		RequestContext.getCurrentInstance().update("form:users");		  
		loggedIn = true;
	}

	public void disconnect() {
		loggedIn = false;
		username = null;
	}

	public void ini() {
		usr = logon.getUsr();
		user = usr.getBenutzer();
		username = usr.getUsername();
		username = username.replaceAll(" ", "_");
		username = username.replace("Ä", "Ae").replace("Ö", "Oe").replace("Ü", "Ue").replace("ä", "ae").replace("ö", "oe").replace("ü", "ue").replace("ß", "ss");	
		neu = true;
	}

	public boolean isNeu() {
		if (username == null) {
			ini();			
		}
		return neu;
	}	  

and the resource

Code: Select all

 @PushEndpoint("/{anfrage}")
@Singleton
public class AnfrageResource {		    
    @OnMessage(encoders = {JSONEncoder.class})
    public FacesMessage onMessage(FacesMessage message) {    	 
        return message;
    }     
}  
 

The growl is in the header of the template.

Code: Select all

<div xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:p="http://primefaces.org/ui" class="header">

	<p:socket onMessage="handleMessageA" channel="/{notify}" />
	<p:socket onMessage="handleMessageA" channel="/{anfrage}" />

	<script>
		function handleMessageA(facesmessage) {
			facesmessage.severity = 'info';
			PF('growl').show([ facesmessage ]);
		}
	</script>

	<h:form id="formheader">
		<p:growl widgetVar="growl" showDetail="true" life="10000"
			escape="false" />

You can test it. Call : http://osretail.de:8082/osRetail/ . You need a secound users it's max .. Klick in the toolbar of the first dialogue after the logon on chat and in the popup login. . Choose the user max and send a first message. You see the message. Of course all users receive the message

Thank you and regards

Peter
PrimeFaces 6.1, Extensions 6.1.1 , Mojarra 2.3 , GlassFish Server Open Source Edition 4.1 (build 13) , atmosphere-runtime 2.4.9 , Open Source ERP with Primefaces http://osretail.de/osRetail/

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

20 Feb 2015, 19:00

magsam wrote:You can test it. Call : http://osretail.de:8082/osRetail/ . You need a secound users it's max .. Klick in the toolbar of the first dialogue after the logon on chat and in the popup login. . Choose the user max and send a first message. You see the message. Of course all users receive the message
I do not fully understand what you describe here, but what I think you mean is that even if you select a specific user to send a private message, everybody receives it, but I cannot realy try to reproduce in osretail (nice extensive app btw, I mentioned that earlier, but hirering a ui designer might help ;-))

One thing that I noticed is that I miss the endpoint for {room}/...

magsam
Posts: 71
Joined: 18 Jun 2012, 17:43
Location: Bavaria, DE
Contact:

23 Feb 2015, 12:48

here ist described what I want

http://stackoverflow.com/questions/1590 ... ppoll-push

This solution no longer works. I think actually there is no solution.
PrimeFaces 6.1, Extensions 6.1.1 , Mojarra 2.3 , GlassFish Server Open Source Edition 4.1 (build 13) , atmosphere-runtime 2.4.9 , Open Source ERP with Primefaces http://osretail.de/osRetail/

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

24 Feb 2015, 16:43

magsam wrote:I think actually there is no solution.
The showcase works...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 43 guests