Im having a problem dynamically loading beans in my program. I have my facelet template like this:
<ui:define name="content"> <f:loadBundle var="Application" basename="start" /> <f:loadBundle var="Messages" basename="#{ApplicationController.bundleName}" /> <h:panelGroup rendered="#{ApplicationController.chosenBean.hasAccess}"> <h:form> <h:outputText value="Error: #{ApplicationController.chosenBean.errorMessage}" id="outputErrorMessage2" /><br /> <h:outputText value="Report running: #{ApplicationController.chosenBean.runningReport}" /><br /> <ui:insert name="application-content" /> <h:commandButton action="#{ApplicationController.chosenBean.actionRunReport}" value="Create report"/> </h:form> </h:panelGroup> <h:panelGroup rendered="#{!ApplicationController.chosenBean.hasAccess}"> <h:outputText value="Err" /> </h:panelGroup> </ui:define> As you can see I want the ApplicationController to decide which Javabean to use. This is done with the following code:
ApplicationController.java public ReportWeb getChosenBean() { String reportName = getReportNameFromServletPath(); //Make first character upper case String beanName = reportName.substring(0, 1).toUpperCase() + reportName.substring(1); logger.log(Level.INFO, "Loading bean with name : {0}", BEAN_PACKET_NAME + beanName); try { if (Class.forName(BEAN_PACKET_NAME + beanName).newInstance() instanceof ReportWeb) { chosenBean = (ReportWeb) Class.forName(BEAN_PACKET_NAME + beanName).newInstance(); } } catch (ClassNotFoundException ex) { Logger.getLogger(ApplicationController.class.getName()).log(Level.SEVERE, null, ex); } catch (InstantiationException ex) { Logger.getLogger(ApplicationController.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(ApplicationController.class.getName()).log(Level.SEVERE, null, ex); } return chosenBean; } All my Javabeans subclass the ReportWeb class, which is an abstract class containing access logic and other convenience methods. The most important method is the
public abstract String actionRunReport(); All my reports implement this one. However in my template I cannot call this method by doing this:
<h:commandButton action="#{ApplicationController.chosenBean.actionRunReport}" value="Create report"/> I recieve no error message, but it just does not work. I have to hardcode the Javabean name like this:
<h:commandButton action="#{AntallHenvendelser.actionRunReport}" value="Create report"/> Does anoyne know why my technique is not working?
EDIT: The method is never called from the action button that dynamically loads the bean.
actionRunReport()method called anyway?@nicknameto notify others about comment replies on posts which are not their own. See also meta.stackexchange.com/questions/43019/… Otherwise you're dependent on their eagerness to take a look back at the post.