我正在使用以下内容实现JSF项目:
我想在项目的所有自定义实体上实施omnifaces.SelectItemsConverter
,我已经按照http://showcase.omnifaces.org/converters/SelectItemsConverter中的指南进行了操作。
问题在于,当我在selectOneMenu上选择一个选项时,转换器在第一次被调用时被调用3次,其余的时间选择值为null,因此在结束时出现NullPointerException并且抛出堆栈跟踪是
java.lang.NullPointerException
at org.omnifaces.util.selectitems.SelectItemsCollector.collectFromParent(SelectItemsCollector.java:109)
at org.omnifaces.util.selectitems.SelectItemsUtils.findValueByStringConversion(SelectItemsUtils.java:50)
at org.omnifaces.converter.SelectItemsConverter.getAsObject(SelectItemsConverter.java:95)
at org.apache.myfaces.shared.renderkit.RendererUtils.getConvertedUISelectOneValue(RendererUtils.java:989)
at org.apache.myfaces.shared.renderkit.html.HtmlMenuRendererBase.getConvertedValue(HtmlMenuRendererBase.java:153)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:662)
at javax.faces.component.UIInput.validate(UIInput.java:598)
at javax.faces.component.UIInput.processValidators(UIInput.java:274)
at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:788)
at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:213)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1019)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at org.primefaces.component.api.UITabPanel.visitTree(UITabPanel.java:920)
at javax.faces.component.UIForm.visitTree(UIForm.java:345)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1047)
at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:1191)
at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartialExecute(PartialViewContextImpl.java:430)
at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:411)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:85)
at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:136)
at javax.faces.component.UIViewRoot$ProcessValidatorPhaseProcessor.process(UIViewRoot.java:1797)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1655)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:909)
at org.apache.myfaces.lifecycle.ProcessValidationsExecutor.execute(ProcessValidationsExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
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:154)
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.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:105)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
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.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
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:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:72)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:282)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:80)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:172)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:774)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我的问题是我无法找到失败,因为异常被抛出我的代码之外,我的代码的相关部分是:
<h:selectOneMenu id="entity"
value="#{backingBean.parentEntity.entity}"
required="#{not empty param[save.clientId] or not empty param[anotherAction.clientId]}"
converter="omnifaces.SelectItemsConverter"
label="Entity">
<p:ajax listener="#{backingBean.onEntityChanged}"
onstart="$( '#parentForm\\:accordionPanel\\:data' ).addClass('loadinggif');"
oncomplete="$( '#parentForm\\:accordionPanel\\:data' ).removeClass('loadinggif');"
update="segment :parentForm:growl :solicitud:guardar :parentForm:accordionPanel:consultantInformation :parentForm:accordionPanel:data"
process="entity segment :parentForm:accordionPanel:consultantInformation :parentForm:accordionPanel:data"
global="false" />
<f:selectItem itemLabel="Select ..." noSelectionOption="true"/>
<f:selectItems value="#{backingBean.entities}" var="entity" itemLabel="#{entity.nombre}" itemValue="#{entity}" />
</h:selectOneMenu>
在我的Backing bean和自定义对象中:
public class BackingBean implements Serializable {
private ParentObject parentEntity;
private List<Entity> entities;
@PostConstruct
public void init() {
this.parentEntity = new ParentObject();
user = (UserDTO) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
}
/**
* This method get called by a
* <f:metadata>
* <f:viewParam name="id" value="#{backingBean.parentObject.id}" />
* <f:viewAction action="#{backingBean.loadObject}" />
* </f:metadata>
*/
public void loadObject() {
inicializarListas();
}
public void initializeLists() {
entities = user.getEntities();
if (entities == null || entities.isEmpty()) {
entities = someController.findEntities();
}
}
//getter and setter for parentEntity
}
任何想法
感谢。
修改
我昨天在这个问题上工作并注意到了错字,但即使修复它,转换器在第一次调用时获得正确的值,其余时间为null值。
答案 0 :(得分:3)
这个问题有三个。
在抛出异常的同时抛出来自SelectItemsCollector.java:109
的NPE令人困惑:
106 } else {
107
108 // A value binding was specified, but of a type we don't support.
109 throw new IllegalArgumentException(String.format(ERROR_UNKNOWN_SELECT_TYPE, value.getClass().toString()));
110 }
因此,value
为null,代码不期望这样。这确实是OmniFaces中的一个错误。我只是fixed它为2.3。
在Mojarra中,当value
为null
时,此代码始终未到达,但在Myfaces中就像您的情况一样(在RichFaces中,如OmniFaces {{3}中所报告的那样)它意外地是。就是这样。一旦你升级到OmniFaces 2.3(目前仅作为SNAPSHOT提供),世界应该再次成功。
选择项value
为null
,因为您在value
中输入了托管bean名称。
<f:selectItems value="#{bakingBean.entities}" ... />
这是一个豆子,而不是一块蛋糕。