Send User Message
  • 15 Apr 2024
  • 1 Minute to read
  • Contributors
  • Dark
    Light

Send User Message

  • Dark
    Light

Article summary

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?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.