Error while extracting values from backing bean

Splash Forums PrettyFaces Users Error while extracting values from backing bean

This topic contains 17 replies, has 3 voices, and was last updated by  Robert 3 years, 1 month ago.

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #24241

    Robert
    Participant

    Hello PrettyFacers,

    my JSF app configures different servers (nodes).

    I have this configuration:

    
        <url-mapping id="configadvancedserver">
            <pattern>/configuration/advancedserver/#{configadvancedserver.nodeLabel}</pattern>
            <view-id>/pages/config/configadvancedserver.xhtml</view-id>
            <query-param name="nodeLabel">#{confignodes.selectedNode}</query-param>
            <action>#{configadvancedserver.init}</action>
        </url-mapping>
    

    When I click a button to go to that page, I get this error in the Glassfish logs:

    
    [#|2013-06-18T16:32:33.115-0500|WARNING|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.lifecycle|_ThreadID=76;_ThreadName=Thread-2;|PrettyFaces: Exception occurred while building URL for MappingId < configadvancedserver >, Error occurred while extracting values from backing bean < #{configadvancedserver.nodeLabel}:null >
    

    I don’t understand why it is trying to *get* a value from the bean I want to go to — that bean does not have values yet. It should *set* that value.

    I thought a pattern like /some/page/#{bean.value} means “when you see a URL that starts with /some/page/ then take the next value (up to the next slash) and inject it into the bean backing bean as value property”.

    What am I missing here?

    Robert

    #24242

    This exception generally occurs when you have links on the page that reference null bean properties. Could you paste your XHTML file? configadvancedserver.xhtml ?

    #24296

    Robert
    Participant

    The whole file is a bit long… here is where it uses the node label:

    <ice:outputText id="CurrentConfigNode" styleClass="currentnode" value="Node: #{configadvancedserver.nodeLabel}"/>
    

    Do you think the problem is with configadvancedserver? I get the crash when I navigate from e.g., configbasicserver to any other page, in this case configadvancedserver. The current page works fine and has the node label. I get to that from a node selection page like this:

    FacesContext.getCurrentInstance().getExternalContext().redirect(("/configuration/basicserver/" + selectedNode);
    

    I am losing the node label when I go from one page to the other.

    Does that make sense?

    Robert

    • This reply was modified 3 years, 1 month ago by  Robert. Reason: Trying to figure out how to mark up code
    • This reply was modified 3 years, 1 month ago by  Robert.
    • This reply was modified 3 years, 1 month ago by  Robert.
    #24302

    The exception you are getting has a “caused by” block which will tell you more about the specific error. But Glassfish logging behaves a bit weird sometimes (or I simply don’t get how to configure it correctly). So perhaps you don’t get the “caused by” in the logs?

    The exception is typically caused by one of the following problems:

    (1) You are using a pretty:link or h:link to render a link to this mapping and the f:param for the path parameter refers to a null value. In the full stacktrace you will typically see one of the two components trying to render.

    (2) You are navigating from an JSF action method by returning pretty:configadvancedserver. If at this point in time #{configadvancedserver.nodeLabel} is null, you will also get this exception.

    I hope this helps a bit. You should try to get the full stacktrace and post it. If the log doesn’t expose the full stacktrace, you could also set a exception breakpoint or something like this.

    #24307

    Robert
    Participant

    Hi Christian,

    here is the whole stack trace:

    [#|2013-06-18T16:32:33.119-0500|WARNING|glassfish3.1.2|org.icefaces.impl.application.ExtendedExceptionHandler|_ThreadID=76;_ThreadName=Thread-2;|queued exception
    javax.faces.FacesException: PrettyFaces: Exception occurred while building URL for MappingId < configadvancedserver >, Error occurred while extracting values from backing bean < #{configadvancedserver.nodeLabel}:null >
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    	at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    	at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:807)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671)
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505)
    	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305)
    	at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    	at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    	at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
    	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
    	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
    	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
    	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    	at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    	at java.lang.Thread.run(Thread.java:722)
    Caused by: com.ocpsoft.pretty.PrettyException: PrettyFaces: Exception occurred while building URL for MappingId < configadvancedserver >, Error occurred while extracting values from backing bean < #{configadvancedserver.nodeLabel}:null >
    	at com.ocpsoft.pretty.faces.beans.ExtractedValuesURLBuilder.buildURL(ExtractedValuesURLBuilder.java:96)
    	at com.ocpsoft.pretty.faces.application.PrettyRedirector.redirect(PrettyRedirector.java:72)
    	at com.ocpsoft.pretty.faces.application.PrettyNavigationHandler.handleNavigation(PrettyNavigationHandler.java:57)
    	at org.icefaces.impl.application.PropagatingNavigationHandler.handleNavigation(PropagatingNavigationHandler.java:74)
    	at org.icefaces.impl.application.ReloadAfterNavigationFix.handleNavigation(ReloadAfterNavigationFix.java:72)
    	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:129)
    	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    	at com.sun.faces.facelets.component.UIRepeat.broadcast(UIRepeat.java:925)
    	at com.sun.faces.facelets.component.UIRepeat.broadcast(UIRepeat.java:925)
    	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:791)
    	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1256)
    	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    	... 67 more
    Caused by: javax.el.ELException: java.lang.NullPointerException
    	at javax.el.BeanELResolver.getValue(BeanELResolver.java:368)
    	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    	at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
    	at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
    	at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
    	at com.ocpsoft.pretty.faces.util.FacesElUtils.getValue(FacesElUtils.java:57)
    	at com.ocpsoft.pretty.faces.beans.ExtractedValuesURLBuilder.buildURL(ExtractedValuesURLBuilder.java:66)
    	... 78 more
    Caused by: java.lang.NullPointerException
    	at com.port25.webui.pages.config.BaseConfigPage.getNodeLabel(BaseConfigPage.java:122)
    	at sun.reflect.GeneratedMethodAccessor537.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
    	... 85 more
    |#]

    Indeed I try to navigate as you described in (2) in your reply.

    And I guess here is what I cannot get my head around: why isn’t the node label injected in the new bean? I understand that it’s null cause this bean is just created and I want to inject the value.

    Is this something about ordering and what happens in what order? Is the outputText rendered before injection happens? If so, wouldn’t that make injection moot?

    I must be missing something here. Or I am not seeing the forest for the trees. Any pointers appreciated.

    Robert

    #24308

    Could you share the code of BaseConfigPage? Especially what is happening in row 122, which is the getter for nodeLabel I guess.

    #24309

    I don’t think that the NullPointerException in BaseConfigPage.getNodeLabel() is caused by nodeLabel being null. This wouldn’t lead to NPE if it’s just a normal getter.

    #24310

    Robert
    Participant

    Well, the NPE does come from node label not being injected.

        // Injected
        public void setNodeLabel(String label) {
            node = nodeCache.get(label);
        }
    
        public String getNodeLabel() {
            return node.getLabel();
        }

    The idea is to inject the node label from the URL, look up that node in a cache, and then load its data in later methods.

    Does that make sense?

    Robert

    #24311

    Yeah, this _should_ work. Could you check whether the setter for the node label is called during the postback or not?

    #24312

    Robert
    Participant

    I added a String member to hold the node label, and that seems to fix it. It’s not clear to me why, but it works. Thanks, Christian!

    #24313

    And also: Is the page action invoked for the postback?

    If not, could you check the URL of the form element in the rendered HTML output? I would be interested to see if it is the pretty URL or not. Are you using a plain h:form?

    #24314

    Oh, good to know. Some problem with the cache perhaps?

    #24315

    Perhaps a scope problem? If the bean has a short scope like “request”, the cache will be empty during the postback.

    #24316

    Robert
    Participant

    We have so many configuration settings that we put them in a simple structured text file (~1,900 lines) and generate the pages and beans from that (~22,000 lines jsf, ~25,000 lines Java beans code). Hence the code is not very readable and has things that may not be necessary. I’ll try to create a minimal example and post that later.

    Robert

    #24317

    Ah, you are generating the JSF/PrettyFaces code. Interesting. Sure, just post an example if you find some time.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.

Comments are closed.