- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback!
Send User Message
Sometimes you want to inform the user about events in the application that is not an error. In that case you can send a user message via java code.
A user message is normally showed below the portal header and above the current portlet.
Send message to the current user
To send a message to the current user in the application you use the following code:
public class PreDialogOut extends AbstractRuleExecute {
@Override
protected boolean postDMProcIn() {
String messageText = loc.getMergedMessage("CAAPPS", "forklift.requested.at.resource", objs);
Message message = new Message(messageText);
sessionWorkspace.getUser().enqueueMessage(message);
}
Send message to another user
To send a message to another user in the application, you have to get the actual session id for that user and use the following code:
public boolean sendUserMessage() {
List<User> users = SystemWorkspace.getInstance().getUsers();
Session s = ((SessionService) sessionWorkspace.getService(CoreRoles.SESSION_ROLE)).getSession();
String baseUrl = s.getRequester().getBaseURL();
boolean first = true;
for (Iterator poolItr = users.iterator(); poolItr.hasNext();) {
User user = (User) poolItr.next();
List sessions = user.getDesktop().getSessionWorkspaces();
for (Iterator itr2 = sessions.iterator(); itr2.hasNext();) {
SessionWorkspace sw = (SessionWorkspace) itr2.next();
if (sw.isHidden()) {
continue;
}
SessionService sessionService = (SessionService) sw.getService(CoreRoles.SESSION_ROLE);
Session session = sessionService.getSession();
if (!sw.getUserData().getLoginName().equals(user.getLoginName())) {
continue;
}
String messageText = mapData.getVariable("Message");
Message msg = new Message(messageText);
String sessionId = sw.getName();
SessionWorkspace sWUser = SessionManager.getSessionWorkspace(sessionId);
sWUser.getUser().enqueueMessage(msg);
}
}
return true;
}
Was this article helpful?