Primefaces autocomplete在春天获得NPE

时间:2015-01-26 13:56:06

标签: spring jsf primefaces autocomplete scope

我试图在spring(4.1.3)+ jsf(2.1.29)上实现primefaces(5.1)的自动完成功能。 这是来自primefaces展示的示例代码。我最终必须给基本概念一个镜头。我的问题是,支持bean按预期工作,但不知何故,建议列表设置为null,因此AutoCompleteRenderer:492的增强for循环抛出NPE,这是预期的。我使用Spring bean来使用AOP。我认为它与spring-jsf-scope相关,但我对如何解决这个问题感到很困惑。任何帮助表示赞赏。

java.lang.NullPointerException: null
at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeSuggestionsAsList(AutoCompleteRenderer.java:492) ~[primefaces-5.1.jar:5.1]
at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeSuggestions(AutoCompleteRenderer.java:393) ~[primefaces-5.1.jar:5.1]
at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeResults(AutoCompleteRenderer.java:123) ~[primefaces-5.1.jar:5.1]
at org.primefaces.component.autocomplete.AutoCompleteRenderer.encodeEnd(AutoCompleteRenderer.java:105) ~[primefaces-5.1.jar:5.1]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:881) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:543) ~[jsf-impl-2.1.29.jar:2.1.29]
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) ~[jsf-impl-2.1.29.jar:2.1.29]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at javax.faces.component.UIForm.visitTree(UIForm.java:371) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:383) ~[jsf-impl-2.1.29.jar:2.1.29]
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:302) ~[jsf-impl-2.1.29.jar:2.1.29]
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60) ~[primefaces-5.1.jar:5.1]
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:973) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) ~[glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:421) ~[jsf-impl-2.1.29.jar:2.1.29]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) ~[jsf-impl-2.1.29.jar:2.1.29]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) ~[jsf-impl-2.1.29.jar:2.1.29]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) ~[jsf-impl-2.1.29.jar:2.1.29]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.29.jar:2.1.29]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [glassfish.jsf_2.0.0.0_2-1-20.jar:2.0.0.0_2-1-20]
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) [weblogic.server.merged.jar:12.1.3.0.0]
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:105) [primefaces-5.1.jar:5.1]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) [weblogic.server.merged.jar:12.1.3.0.0]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.1.3.RELEASE.jar:4.1.3.RELEASE]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) [weblogic.server.merged.jar:12.1.3.0.0]
at tr.com.innova.portal.web.filter.XSSFilter.doFilter(XSSFilter.java:19) [XSSFilter.class:na]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) [com.oracle.css.weblogic.security.wls_7.1.0.0.jar:CSS 7.1 0.0]
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311) [weblogic.server.merged.jar:12.1.3.0.0]
at weblogic.work.ExecuteThread.run(ExecuteThread.java:263) [weblogic.server.merged.jar:12.1.3.0.0]

我的支持bean(注意它使用自定义范围管理):

import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import tr.com.innova.portal.model.entity.Employee;
import tr.com.innova.portal.model.entity.EmployeeEvaluation;
import tr.com.innova.portal.service.business.api.EmployeeService;
import tr.com.innova.portal.service.business.api.EvaluationService;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Component(value = "employeeAutocompleteView")
@Scope("session")
public class EmployeeAutocompleteView {
    private String name;
    private Employee current;
    private List<Employee> employees;

    @Autowired
    private EmployeeService employeeService;

    @Autowired
    private EvaluationService evaluationService;

    @PostConstruct
    public void init(){
        this.current = null;
        this.name = null;
    }

    public List<String> completeText(String query) {
        List<String> results = new ArrayList<String>();
        for (int i=0 ; i< 10 ; i++) {
            results.add(query + i);
        }
        return results;
    }

    public void onItemSelect(SelectEvent event) {
        fillReport();
        RequestContext.getCurrentInstance().update(":reportForm");
    }

我的xhtml:

    <h:form>
        <div>
            <p:autoComplete id="employeeSelector" 
                value="#{employeeAutocompleteView.name}" 
                completeMethod="#{employeeAutocompleteView.completeText}"/>
        </div>
    </h:form>

2 个答案:

答案 0 :(得分:1)

我们想通了。 pom.xml中有jsf的mojarrra和sun实现。我不知道它是如何到达或为什么,但删除太阳实施解决了这个问题。希望这可以帮助将来的某个人。

答案 1 :(得分:0)

另一个原因:p:在h:form标签之外自动完成。