繁体   English   中英

JSF2:处理从WebListener到ManagedBeans的RMI连接

[英]JSF2: Handling RMI Connection from WebListener to ManagedBeans

初始问题

嗨,

我使用@WebListener类在应用程序部署时启动RMI连接。 这将我的JSF前端与后端连接起来。

很好!

接下来我想将连接交给ManagedBean,因为我想使用连接来保存bean之外的东西,因为weblistener不能从xhtml页面访问。

我试图将managedProperty放入该类,但我认为这是不允许的。 那怎么办呢?

@WebListener
public class Config implements ServletContextListener {

public static final String SERVER_NAMING = "xxx";
public static final String SERVER_HOST = "xxx"; 

public static FrontendCommInterface server;


public void contextInitialized(ServletContextEvent event) {
    try {

        server = (FrontendCommInterface) Naming.lookup("rmi://" + SERVER_HOST + "/" + SERVER_NAMING); 
            System.out.println("Connection successfull!");
//HERE THE SERVER SHOULD HANDED TO ANOTHER MANAGEDBEAN !!! BUT HOW TO DO THAT??? 

        } catch (MalformedURLException e) {
        System.out.print("Error: " + e.getLocalizedMessage());
    } catch (RemoteException e) {
        System.out.print("Error: " + e.getLocalizedMessage());
    } catch (NotBoundException e) {
        System.out.print("Error: " + e.getLocalizedMessage());
    }
}

public void contextDestroyed(ServletContextEvent event) {
    // Do stuff during webapp's shutdown.
} 

您需要创建bean并自己放入应用程序范围。

event.getServletContext().setAttribute("communication", new Communication(server));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM