Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3613598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:08:41+00:00 2026-05-18T22:08:41+00:00

Im having a problem dynamically loading beans in my program. I have my facelet

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:08:41+00:00Added an answer on May 18, 2026 at 10:08 pm

    The root cause is likely because the rendered attribute of the action component (or at least one of its parents) has evaluated false during the request of the form submit. This way the action won’t be invoked. You need to ensure that the rendered attribute doesn’t evaluate false while the request of form submit is to be processed.

    See also this answer for an overview of possible causes of an action component not being invoked.


    Regardless, the approach as you’ve shown as far is plain inefficient. I’d make the ApplicationController request scoped and load the chosen bean as follows:

    public class ApplicationController {
    
        private ReportWeb chosenBean;
    
        public ApplicationController() {
            chosenBean = findBean(getReportNameFromServletPath(), ReportWeb.class);
        }
    
        public static <T> T findBean(String managedBeanName, Class<T> beanClass) {
            FacesContext context = FacesContext.getCurrentInstance();
            return beanClass.cast(context.getApplication().evaluateExpressionGet(context, "#{" + managedBeanName + "}", beanClass);
        }
    
        // ...
    }
    

    This way it is loaded only once per request instead of at least once per EL expression which is calling the getter (which can be at least twice as much when used inside rendered attribute).

    This way you’re also grabbing the bean which is actually managed by JSF instead of creating it (twice!) manually inside a getter. If JSF has already created an instance, exactly this one will be returned. If JSF hasn’t already created it, a new one will be created and put in the scope accordingly before it’s returned.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with some jquery animations. I have dynamically created divs with
i'm having a problem with dynamically loaded forms - instead of using the action
(EDIT: I have asked the wrong question. The real problem I'm having is over
hello i am having a problem with dynamically added rows to jquery tablesorter, i
I am having a problem assigning a control to dynamically added elements (inside the
We're having problem with a huge number of legacy stored procedures at work. Do
I'm having problem in the following line: rd.PrintOptions.PaperSize = PaperSize.PaperFanfoldStdGerman; it throws an exception
Having a problem getting a TreeView control to display node images. The code below
Having a problem trying to create a function, as part of a BizTalk helper
Im having a problem with a final part of my assignment. We get in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.