Primefaces更新另一个会话组件

时间:2018-06-04 03:42:58

标签: java session primefaces

我正在使用带有tomcat 8.1的primefacs 6.1。在我的页面中需要根据会话ID

更新notificationPanel
<p:ouputPanel id="notificationId">
    #{page.notificationCount}
</p:ouputpanel>

在会话监听器类中我将尝试

public class SessionAttributeListener implements HttpSessionAttributeListener
{
 private final Logger logger = Logger.getLogger(getClass());

    @Override
    public void attributeAdded(HttpSessionBindingEvent event)
    {                                      
      for (Object a : SessionLife.previousSessionId())
      {    
       HttpSession previousSession = SessionLife.getSession((String) a);

       if (previousSession.getId()!=null && event.getSession().getId()!=null 
                        && (previousSession.getId() != event.getSession().getId()))
       {                       

        String userName = previousSession.getAttribute("userLoginName").toString();
        Main user = (Main) getManagedBeanObject(Main.class.getSimpleName());
        if (StringUtils.equalsIgnoreCase(userName, "user2"))
        {
          user.setNotificationCount(2);
          RequestContext.getCurrentInstance().execute("notificationId");
        }

      }
   }
   @Override
   public void attributeRemoved(HttpSessionBindingEvent event)
   {

   }
   @Override
   public void attributeReplaced(HttpSessionBindingEvent event)
   {

   }

   public Object getManagedBeanObject(String className)
   {
     FacesContext facesContext = FacesContext.getCurrentInstance();
     ELResolver resolver = facesContext.getApplication().getELResolver();
     return resolver.getValue(facesContext.getELContext(), null, className);
   }           

    }
}

我的疑问是在我的应用程序中现在登录user1,user2和user3以及现在的当前登录名user4.I需要当前用户来更新user2 outputPanel(notificationId)吗?

0 个答案:

没有答案
相关问题