[英]JSF2: Handling RMI Connection from WebListener to ManagedBeans
Hi, 嗨,
I use a @WebListener Class to initiate a RMI connection at application deployment. 我使用@WebListener类在应用程序部署时启动RMI连接。 That connects my JSF frontend with a backend.
这将我的JSF前端与后端连接起来。
That works fine! 很好!
Next I want to hand the connection to a ManagedBean because I want to use the connection to eg save something out of a bean, since weblistener is not accessible out of xhtml pages. 接下来我想将连接交给ManagedBean,因为我想使用连接来保存bean之外的东西,因为weblistener不能从xhtml页面访问。
I tried to put a managedProperty into that class but I think that's not allowed. 我试图将managedProperty放入该类,但我认为这是不允许的。 So how to do that?
那怎么办呢?
@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.