找不到JSF 2 FacesConverter ManagedProperty

时间:2013-06-12 07:09:59

标签: jsf primefaces converter managed-bean managed-property

我在WebSphere Application Server 8上使用Apache myfaces 2.0和Primefaces 3.5。

我有一个ApplicationConverter和一个包含应用程序列表(类)的ManagedBean。

转换器看起来像:

@ManagedBean
@RequestScoped
public class ApplicationConverter implements Converter {
    @ManagedProperty(value = "#{requirement.jvmcreate.applications}")
    private List<Application> applications;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component,
            String value) throws ConverterException {
        if(value == null)
            return null;
        for(Application app : applications)
            if(app.getName().equals(value))
                return app;
        return null;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component,
            Object value) throws ConverterException {
        if(value != null && value instanceof Application )
            return ((Application)value).getName();
        return "";
    }

}

应用程序列表位于此层次结构中:

@ManagedBean(name = "requirement")
@SessionScoped
public class Requirement implements Serializable {
    private static final long serialVersionUID = 1L;
    private JVMCreate jvmcreate;
        ...
}

public class JVMCreate implements Serializable {
    private List<Application> applications;
    private Application selectedApp;
}

当我需要来自primefaces的select组件中的转换器时:

<p:selectOneListbox value="#{requirement.jvmcreate.selectedApp}" converter="#{applicationConverter }" var="appl">
    <f:selectItems value="#{requirement.jvmcreate.applications}" var="app" itemLabel="#{app.name }" itemValue="app" />
</p:selectOneListbox>

但我得到以下例外:

12.06.13 08:51:19:652 CEST] 0000044a FaceletViewDe E   Error Rendering View[/index.xhtml]
                                 javax.el.ELException: /jvmcreate_tab.xhtml at line 88 and column 120 converter="#{applicationConverter }": Property 'applications' not found on type converter.ApplicationConverter
    at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:93)
    at javax.faces.component.UIOutput.getConverter(UIOutput.java:101)
    at org.primefaces.component.selectonelistbox.SelectOneListboxRenderer.encodeSelectItems(SelectOneListboxRenderer.java:191)
    at org.primefaces.component.selectonelistbox.SelectOneListboxRenderer.encodeInput(SelectOneListboxRenderer.java:97)
    at org.primefaces.component.selectonelistbox.SelectOneListboxRenderer.encodeMarkup(SelectOneListboxRenderer.java:62)
    at org.primefaces.component.selectonelistbox.SelectOneListboxRenderer.encodeEnd(SelectOneListboxRenderer.java:42)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:626)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:622)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:143)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:107)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:63)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:47)
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeContent(FieldsetRenderer.java:90)
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeMarkup(FieldsetRenderer.java:72)
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeEnd(FieldsetRenderer.java:46)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:63)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:47)
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:202)
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:119)
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:56)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:626)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:622)
    at org.primefaces.component.wizard.WizardRenderer.encodeStep(WizardRenderer.java:77)
    at org.primefaces.component.wizard.WizardRenderer.encodeEnd(WizardRenderer.java:59)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:626)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.processRenderComponent(PartialViewContextImpl.java:559)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:537)
    at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:207)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:773)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:991)
    at javax.faces.component.UIForm.visitTree(UIForm.java:269)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:991)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:793)
    at javax.faces.component.UIComponentBase.visitTree(UIComponentBase.java:991)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartialRendering(PartialViewContextImpl.java:426)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:346)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:88)
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:390)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:617)
    at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1320)
    at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
    at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
    at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:886)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)
Caused by: javax.faces.el.EvaluationException: Property 'applications' not found on type converter.ApplicationConverter
    at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:80)
    at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:116)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283)
    at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
    ... 72 more
Caused by: javax.el.PropertyNotFoundException: Property 'applications' not found on type converter.ApplicationConverter
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:225)
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:202)
    at javax.el.BeanELResolver.property(BeanELResolver.java:312)
    at javax.el.BeanELResolver.setValue(BeanELResolver.java:135)
    at javax.el.CompositeELResolver.setValue(CompositeELResolver.java:71)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.setValue(FacesCompositeELResolver.java:182)
    at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:349)
    at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:169)
    at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
    at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
    at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
    at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
    ... 78 more

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

@ManagedProperty注释适用于属性 - 您应该将getter和setter方法添加到applications类中的ApplicationConverter字段。

请参阅here