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

  • SEARCH
  • Home
  • 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 7055705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:46:50+00:00 2026-05-28T03:46:50+00:00

I’m having trouble with a DataTable. I have a SelectOneMenu component with 3 options.

  • 0

I’m having trouble with a DataTable.
I have a SelectOneMenu component with 3 options. Every option should render a DataTable with different information.

My xhtml page is working (I tested it with a simple code), but it seems that my backing bean is not working as I was expecting. When I run the page throws an error message.

My xhtml looks like

<h:form>
        <h:outputLabel for="reporte" value="Tipo de reporte: " />
        <h:selectOneMenu id="reporte"
                         value="#{reportController.type}">
            <f:selectItem itemLabel="Seleccione tipo de reporte..." itemValue="null" />
            <f:selectItems value="#{reportController.reportType}" />
            <f:ajax execute="@form" render="@form" />
        </h:selectOneMenu>




        <h:panelGrid id="porSistema"
                     rendered="#{reportController.type == 'Por sistema'}">
            <h:dataTable value="#{reportController.list}" var="item"
                         border="1">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Nombre del archivo"/>
                    </f:facet>
                    <h:outputText value="#{item.fileName}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Registros correctos"/>
                    </f:facet>
                    <h:outputText value="#{item.registersOk}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Registros incorrectos"/>
                    </f:facet>
                    <h:outputText value="#{item.registersNok}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Registros procesados"/>
                    </f:facet>
                    <h:outputText value="#{item.registers}"/>
                </h:column>
            </h:dataTable>
        </h:panelGrid>
    </h:form>

The bean is

@ManagedBean
@ViewScoped
public class ReportController {

    List<Object> list = new ArrayList<Object>();
    String type;
    String[] reportType = new String[]{"Por sistema",
        "Por programa y componente",
        "Por estatus de pago"};

    @PostConstruct
    public void init() {
        if (type.equals("Por sistema")) {
            list.add(new ReporteSistema("A", "B", "C", "D"));
        } else if (type.equals("Por programa y componente")) {
            list.add(new ReporteProgramaComponenteA("E", "F", "G", "H", "I", "J"));
        } else if (type.equals("Por estatus de pago")) {
            list.add(new ReporteProgramaComponenteB("K", "L", "M", "N"));
        }
    }

    public String[] getReportType() {
        return reportType;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<Object> getList() {
        return list;
    }

    public void setList(List<Object> list) {
        this.list = list;
    }
}

and the stack trace is

com.sun.faces.mgbean.ManagedBeanCreationException: Se ha producido un error al realizar la inyección de recurso en el bean administrado reportController
    at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:169)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:648)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:749)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:844)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:298)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at mx.gob.sagarpa.NoCacheFilter.doFilter(NoCacheFilter.java:29)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:349)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Caused by: com.sun.faces.spi.InjectionProviderException
    at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:119)
    at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:99)
    at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
    ... 56 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor85.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:117)
    ... 58 more
Caused by: java.lang.NullPointerException
    at mx.gob.sagarpa.beans.ReportController.init(ReportController.java:32)
    ... 62 more
  • 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-28T03:46:51+00:00Added an answer on May 28, 2026 at 3:46 am

    You seem to be misunderstanding the purpose of the @PostConstruct. This annotation is to be used to specify methods which are to be executed directly after bean’s construction. This annotation allows you to execute code after injection of managed properties specified by @ManagedProperty and all other dependencies such as @Inject or @EJB. Those injected properties and dependencies are namely not available inside the bean’s constructor (a fully constructed instance of the bean has to be obtained first before all injections can take place, of course). The @PostConstruct of a view scoped bean is not invoked when you send an ajax request on it. It’s only invoked when you initially open the page in the browser.

    You actually want to invoke that method when the ajax event is fired. You need to change the view and bean as follows in order to get it to work.

    <h:selectOneMenu id="reporte" value="#{reportController.type}">
        <f:selectItem itemLabel="Seleccione tipo de reporte..." itemValue="null" />
        <f:selectItems value="#{reportController.reportType}" />
        <f:ajax execute="@form" listener="#{reportController.changeType}" render="@form" />
    </h:selectOneMenu>
    

    (note the new listener attribute)

    and

    public void changeType() { // No, do not put @PostConstruct on it!
        if ("Por sistema".equals(type)) {
            list.add(new ReporteSistema("A", "B", "C", "D"));
        } else if ("Por programa y componente".equals(type)) {
            list.add(new ReporteProgramaComponenteA("E", "F", "G", "H", "I", "J"));
        } else if ("Por estatus de pago".equals(type)) {
            list.add(new ReporteProgramaComponenteB("K", "L", "M", "N"));
        }
    }
    

    Also note that I swapped the both sides of the equals() so that you can guarantee that it will never throw NPE. If the type happen to be null, then it will simply be compared as non-equal. When you actually invoked equals() on something which is null, you will guaranteed get a NPE (that’s what the whole exception stands for! see also its javadoc).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.