the message is not sent to private

UI Components for JSF
Post Reply
blakingFaces
Posts: 12
Joined: 30 May 2014, 09:46

15 Sep 2014, 16:27

hi to all!
I a problem with primefaces push! I try the example of the cat is in the vitrin,
works well but as I sign out and I log the message is not sent to private .

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

16 Sep 2014, 17:47

share your PrimeFaces Push xhtml and java bean code, and see my signature below, and share version of browser, PrimeFaces, container (tomcat, glassfish, jboss, weblogic, ...), etc...
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

blakingFaces
Posts: 12
Joined: 30 May 2014, 09:46

17 Sep 2014, 09:47

here is my xhtml page :

Code: Select all


<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/WEB-INF/template.xhtml">

	<ui:define name="head">
		<style type="text/css">
.value {
	font-weight: bold;
}

.ui-datatable {
	margin-bottom: 25px
}

.ui-datatable .ui-datatable-footer {
	text-align: left;
}

.ui-datalist ul {
	padding: 0 0 0 10px;
	margin: 5px 0;
}

.ui-datatable .ui-button-icon-only .ui-button-text {
	padding: 0;
	line-height: 1.2;
}

.messageInput {
	width: 400px;
}

.publicColumn {
	width: 80%;
}

.usersColumn {
	width: 20%;
}

.vtop {
	vertical-align: top;
}

.chatlogs {
	height: 200px;
	overflow: auto;
	padding: 0.5em 1em 0.5em 0.5em;
}

.usersList {
	height: 200px;
	overflow: auto;
}

.usersList ul {
	list-style-type: none;
	padding-left: 10px;
}

.usersList ul li {
	margin-bottom: 2px;
}

.usersList .ui-button-text {
	padding: 0;
}
</style>
	</ui:define>

	<ui:define name="title">
        Incident
	</ui:define>

	<ui:define name="implementation">
		<h:form id="incident">

			<p:remoteCommand name="updateList" update="users" process="@this" />
			<p:growl id="msg" showDetail="true" />
			<p:tabView orientation="left" id="tabView">

				
				<p:tab title="Vos Tickets" id="tab2">


					<p:panel id="panelx" header="Tickets" toggleable="true">

						<h:panelGrid columns="2" style="margin-bottom:10px"
							cellpadding="5">

							<p:selectOneRadio id="console"
								value="#{ticketBean.afficheTicket}">
								<f:selectItem itemLabel="Tous  " itemValue="tous" />
								<f:selectItem itemLabel="  En attente" itemValue="En attente" />
								<f:selectItem itemLabel="  En cours" itemValue="En cours" />
								<f:selectItem itemLabel="  Resolu" itemValue="Resolu" />
								<f:selectItem itemLabel=" Rejeter" itemValue="Rejeter" />
								<p:ajax event="change" update="ticketTab"></p:ajax>
							</p:selectOneRadio>


						</h:panelGrid>
					</p:panel>


					<p:spacer height="20"></p:spacer>

					<p:dataTable value="#{ticketBean.ticketList}" var="o" rows="5"
						paginator="true"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15,25,50" id="ticketTab"
						widgetVar="ticketTable" style="wi"
						emptyMessage="Aucune Information">

						<p:column>
							<f:facet name="header">Categorie</f:facet>




							<h:outputText value="#{o.categorie}" />
						</p:column>

						<p:column>

							<f:facet name="header">Titre</f:facet>



							<h:outputLabel value="#{o.titre}" />
						</p:column>

						<p:column>

							<f:facet name="header">Etat</f:facet>



							<h:outputLabel value="#{o.etat}" />
						</p:column>

						<p:column>

							<f:facet name="header">Date</f:facet>



							<h:outputLabel value="#{o.date}" rendered="#{not o.date}" />
						</p:column>


						<p:column style="width:5%;text-align: center">
							<p:commandButton update=":incident:incidentDetail"
								oncomplete="PF('incidentDialog').show()" icon="ui-icon-search"
								title="View">
								<f:setPropertyActionListener value="#{o}"
									target="#{ticketBean.ticket}" />
							</p:commandButton>
						</p:column>

					</p:dataTable>



				</p:tab>
				<p:tab title="Statistique" id="tab3">

				</p:tab>
			</p:tabView>

			<p:dialog header="Incident Info" widgetVar="incidentDialog"
				modal="true" showEffect="drop" hideEffect="drop" resizable="false">

				<p:outputPanel id="incidentDetail">
					<h:panelGrid columns="2" cellpadding="5"
						rendered="#{not empty ticketBean.ticket}">

						<h:outputLabel for="demandeur" value="Demandeur" />

						<h:inputText id="demandeur" value="#{ticketBean.partenaire}"
							disabled="true" />

						
						<h:outputLabel for="techt" value="Technicien"
							rendered="#{menuBean.valueAffectationTicket}"></h:outputLabel>

						<p:selectOneMenu value="#{ticketBean.technicien2}" filter="true"
							filterMatchMode="startsWith" panelStyle="width:190px" id="techt"
							rendered="#{menuBean.valueAffectationTicket}" effect="drop"
							height="150" label="Produit" style="width: 25%;">
							<f:selectItem itemLabel="--Select--" itemValue="" />
							<f:selectItems value="#{ticketBean.technicienList2}" />
						</p:selectOneMenu>

						<h:outputLabel for="categ" value="Affecte A"></h:outputLabel>

						<h:inputText id="categ" value="#{ticketBean.technicien3}"
							disabled="true" />

						<h:outputLabel for="titr" value="Titre"></h:outputLabel>

						<h:inputText id="titr" value="#{ticketBean.ticket.titre}"
							disabled="true" />

						<h:outputLabel for="descript" value="Description :"
							rendered="#{not chatView.loggedIn}" />

						<h:inputTextarea id="descript"
							value="#{ticketBean.ticket.description}" rows="8" cols="100"
							disabled="true" rendered="#{not chatView.loggedIn}" />

						<h:outputLabel value="Resolution"></h:outputLabel>
						<p:fieldset id="container" legend="Resolution" toggleable="true">

							<h:panelGroup rendered="#{chatView.loggedIn}">
								<h:panelGrid columns="2"
									columnClasses="publicColumn,usersColumn" style="width:100%">
									<p:outputPanel id="public" layout="block"
										styleClass="ui-corner-all ui-widget-content chatlogs">

										<ui:repeat var="boucle" value="#{chatView.messages}">

											<h:outputLabel value="#{boucle}"></h:outputLabel>
											<br />

										</ui:repeat>

									</p:outputPanel>

									<p:dataList id="users" var="user" value="#{chatUsers.users}"
										styleClass="usersList" emptyMessage="Aucun User"
										rendered="#{chatView.cacheList}">
										<f:facet name="header">
                                Users
                            </f:facet>

										<p:commandButton title="Chat" icon="ui-icon-comment"
											oncomplete="PF('pChat').show()"
											update=":incident:privateChatContainer">
											<f:setPropertyActionListener value="#{user}"
												target="#{chatView.privateUser}" />
										</p:commandButton>
                            #{user}
                        </p:dataList>
								</h:panelGrid>

								<p:separator />

								<p:inputText value="#{chatView.globalMessage}"
									styleClass="messageInput" />
								<p:spacer width="5" />
								<p:commandButton value="Send"
									actionListener="#{chatView.sendPrivate2()}"
									oncomplete="$('.messageInput').val('').focus()" />
								<p:spacer width="5" />
								<p:commandButton value="Disconnect"
									action="#{chatView.disconnect}" global="false"
									update=":incident:incidentDetail"/>
							</h:panelGroup>

							<h:panelGroup rendered="#{not chatView.loggedIn}">
                    Login : <p:inputText value="#{chatView.username}"
									disabled="true" />

								<p:spacer width="5" />
								<p:commandButton value="OK" action="#{chatView.login}"
									update="incidentDetail" icon="ui-icon-person" disabled="false">
									<f:setPropertyActionListener
										value="#{ticketBean.ticket.ticketId}"
										target="#{chatView.ticketId}" />
								</p:commandButton>
							</h:panelGroup>

						</p:fieldset>

						<h:outputLabel for="dateOuv" value="Date de la demande : "></h:outputLabel>

						<h:inputText id="dateOuv" value="#{ticketBean.ticket.date}"
							disabled="true" />

						<h:outputLabel for="dateResol" value="Date de la resolution : "
							rendered="#{not chatView.loggedIn}"></h:outputLabel>

						<h:inputText id="dateResol" value=""
							disabled="true" rendered="#{not chatView.loggedIn}" />

						
						<h:outputLabel for="etat2" value="Etat : "
							rendered="#{not chatView.loggedIn}"></h:outputLabel>

						<p:selectOneMenu value="#{ticketBean.etat2}" filter="true"
							filterMatchMode="startsWith" panelStyle="width:190px" id="etat2"
							rendered="#{not chatView.loggedIn}"  effect="drop" height="150"
							label="Produit" style="width: 25%;">
							<f:selectItem itemLabel="--Select--" itemValue="" />
							
							<f:selectItems value="#{ticketBean.etatList}" />
						</p:selectOneMenu>

					</h:panelGrid>
					<p:separator></p:separator>
					<h:commandButton value="Enregistrer"
						
						action="#{ticketBean.SaveActions()}" styleClass="sansLabel">

						<f:setPropertyActionListener value="#{ticketBean.ticket.ticketId}"
							target="#{ticketBean.ticketId2}" />
						<f:ajax execute="incidentDetail" render="incidentDetail" />
					</h:commandButton>
				</p:outputPanel>
			</p:dialog>

			<p:dialog widgetVar="pChat" header="Private Chat" modal="true"
				showEffect="fade" hideEffect="fade">
				<h:panelGrid id="privateChatContainer" columns="2"
					columnClasses="vtop,vtop">
					<p:outputLabel for="pChatInput" value="To: #{chatView.privateUser}" />
					<p:inputTextarea id="pChatInput" value="#{chatView.privateMessage}"
						rows="5" cols="30" />

					<p:spacer />
					<p:commandButton value="Send"
						actionListener="#{chatView.sendPrivate}"
						oncomplete="PF('pChat').hide()" />
				</h:panelGrid>
			</p:dialog>
		</h:form>
		<p:socket onMessage="handleMessage" channel="/{room}"
			autoConnect="false" widgetVar='subscriber' />
		<script type="text/javascript">
			function handleMessage(message) {
				var chatContent = $(PrimeFaces
						.escapeClientId('incident:public')), text = (message.user) ? message.user
						+ ':' + message.text
						: message.text;

				chatContent.append(text + '<br />');

				//keep scroll
				chatContent.scrollTop(chatContent.height());

				if (message.updateList) {
					updateList();
				}
			}
		</script>
	</ui:define>
</ui:composition>




here is my managedBean :

Code: Select all


@ManagedBean
@ViewScoped
public class ChatView implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 890730923295693231L;

	private final EventBus eventBus = EventBusFactory.getDefault().eventBus();

	@ManagedProperty("#{chatUsers}")
	private ChatUsers users;
	private String privateMessage;
	private String globalMessage;
	private String username;
	private boolean loggedIn, cacheList;
	private String ticketId;
	private String privateUser;
	private ValidatorLogin validatorLogin = null;
	private static final String CHANNEL = "/{room}/";
	private String login;
	private List<String> usersTicket = new ArrayList<String>();
	private List<String> messages = new ArrayList<String>();
	private TicketDAO ticketDAO = null;

	@PostConstruct
	public void init() {

		ticketDAO = new TicketDAO();

	}

	@ManagedProperty("#{identificationBean}")
	private IdentificationBean identification;

	public ChatUsers getUsers() {
		return this.users;
	}

	public void setUsers(ChatUsers users) {
		this.users = users;
	}

	public String getPrivateUser() {
		return this.privateUser;
	}

	public void setPrivateUser(String privateUser) {
		this.privateUser = privateUser;
	}

	public String getGlobalMessage() {
		return this.globalMessage;
	}

	public void setGlobalMessage(String globalMessage) {
		this.globalMessage = globalMessage;
	}

	public String getPrivateMessage() {
		return this.privateMessage;
	}

	public void setPrivateMessage(String privateMessage) {
		this.privateMessage = privateMessage;
	}

	public String getUsername() {

		username = identification.getLogin();

		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public boolean isLoggedIn() {
		return this.loggedIn;
	}

	public void setLoggedIn(boolean loggedIn) {
		this.loggedIn = loggedIn;
	}

	public void sendGlobal() {
		this.eventBus.publish("/{room}/*", this.username.toUpperCase() + " :> "
				+ this.globalMessage);
		this.globalMessage = null;
	}

	public void sendPrivate() {
		this.eventBus.publish("/{room}/" + this.privateUser, "[PM] "
				+ this.username.toUpperCase() + " :> " + this.privateMessage);

		this.privateMessage = null;

	}

	public void sendPrivate2() {
		String val1 = "";
		for (String val : this.users.getUsersTicket()) {

			val1 = (String) val.subSequence(val.indexOf("---") + 3,
					val.length());

			if (val1.trim().equals(ticketId)) {

				this.eventBus.publish("/{room}/" + val,
						"" + this.username.toUpperCase() + " :> "
								+ this.globalMessage);

			}
		}

		ticketDAO.InsertAction2(ticketId, this.username.toUpperCase() + " :> "
				+ this.globalMessage);
		this.globalMessage = null;
	}

	public void login() {
		RequestContext requestContext = RequestContext.getCurrentInstance();

		if (this.users.contains(this.username)) {
			this.users.remove(this.username);
			this.users.getUsersTicket().remove(username + "---" + ticketId);
			// this.users.getUsersTicket().add(username+"---"+ticketId);
			// this.users.add(this.username);
			this.loggedIn = false;

			// FacesContext.getCurrentInstance().addMessage(null,new
			// FacesMessage(FacesMessage.SEVERITY_ERROR,"Username taken",
			// "Try with another username."));
			// requestContext.update("incident:msg");

		} else {

			this.users.add(this.username);
			this.users.getUsersTicket().add(username + "---" + ticketId);
			requestContext.execute("PF('subscriber').connect('/"
					+ this.username + "---" + ticketId + "')");
			this.loggedIn = true;

		}
	}

	public void disconnect() {
		//RequestContext requestContext = RequestContext.getCurrentInstance();

		this.users.remove(this.username);
		this.users.getUsersTicket().remove(username + "---" + ticketId);
		//requestContext.execute("PF('subscriber').disconnectconnect('/"+ this.username + "---" + ticketId + "')");
		System.out.println("Disconnect ! ");
		// this.eventBus.publish("/{room}/*", this.username +
		// " left the channel.");
		RequestContext.getCurrentInstance().update("incident:users");
		this.loggedIn = false;
		// this.username = null;
	}

	public String getTicketId() {
		return ticketId;
	}

	public void setTicketId(String ticketId) {
		this.ticketId = ticketId;
	}

	public IdentificationBean getIdentification() {
		return identification;
	}

	public void setIdentification(IdentificationBean identification) {
		this.identification = identification;
	}

	public String getLogin() {

		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public List<String> getUsersTicket() {
		return usersTicket;
	}

	public void setUsersTicket(List<String> usersTicket) {
		this.usersTicket = usersTicket;
	}

	public boolean isCacheList() {
		return cacheList;
	}

	public void setCacheList(boolean cacheList) {
		this.cacheList = cacheList;
	}

	public List<String> getMessages() {
		messages.clear();

		messages = ticketDAO.msgList(ticketId);
		return messages;
	}

	public void setMessages(List<String> messages) {
		this.messages = messages;
	}

}





blakingFaces
Posts: 12
Joined: 30 May 2014, 09:46

17 Sep 2014, 09:51

I use primefaces 5.0 and apache tomcat 7.0.30

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

17 Sep 2014, 13:04

if you copy/pasted the PrimeFaces Push - Chat example source code from the showcase, then it is designed/implemented to only push to public when you logout (or disconnect).

i looked at your code (below), and you have code commented out.

Code: Select all

   public void disconnect() {
      //RequestContext requestContext = RequestContext.getCurrentInstance();

      this.users.remove(this.username);
      this.users.getUsersTicket().remove(username + "---" + ticketId);
      //requestContext.execute("PF('subscriber').disconnectconnect('/"+ this.username + "---" + ticketId + "')");
      System.out.println("Disconnect ! ");
      // this.eventBus.publish("/{room}/*", this.username +
      // " left the channel.");
      RequestContext.getCurrentInstance().update("incident:users");
      this.loggedIn = false;
      // this.username = null;
   }
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

blakingFaces
Posts: 12
Joined: 30 May 2014, 09:46

18 Sep 2014, 16:04

I just remove the comments but after disconnections and reconnection to chat, send private messages does not work!

Code: Select all

 public void disconnect() {
    

      this.users.remove(this.username);
      this.users.getUsersTicket().remove(username + "---" + ticketId);
    
     
      this.eventBus.publish("/{room}/*", this.username +" left the channel.");
      RequestContext.getCurrentInstance().update("incident:users");
      this.loggedIn = false;
      this.username = null;
   }

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests