[英]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.