0

我有一个@Embeddable包含属性的类@Enumerated。我想@Enumerated在 selectOneMenu primefaces 中显示此属性的值。问题是当我尝试显示我的页面时,它返回一个@Enumeratednull 异常,我不知道如何解决这个问题。

枚举

public enum EstadosDoBrasil {
    AC,
    AL,
    AM,
    AP,
    BA,
    CE,
    DF,
    ES,
    FN,
    GO,
    MA,
    MG,
    MS,
    MT,
    PA,
    PB,
    PE,
    PI,
    PR,
    RJ,
    RN,
    RO,
    RR,
    RS,
    SC,
    SE,
    SP,
    TO; 
}

可嵌入

@Embeddable
public class Endereco {

    @NotNull @Size(min=5, message="Informe o endereço")
    private String endereco;

    @NotNull
    private Integer numero;

    private String complemento;

    @NotNull @Size(min=5, message="Informe a cidade")
    private String cidade;

    @NotNull @Size(min=3, message="Informe o bairro")
    private String bairro;

    private String cep;

    @Enumerated(EnumType.STRING)
    private EstadosDoBrasil uf;
    //gets sets

实体域

@Entity
@NamedQueries({
    @NamedQuery(name=UnidadeEscolar.FIND_ALL, query="SELECT ue FROM UnidadeEscolar ue")
})
public class UnidadeEscolar implements Serializable{    
    private static final long serialVersionUID = 1L;


    public static final String FIND_ALL = "unidadeEscolar.findAll";

    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    @NotNull @Size(min=5, message="Informe o nome da unidade escolar")
    private String nome;

    private String departamento;

    @Embedded
    private Endereco endereco;

public UnidadeEscolar() {
        endereco = new Endereco();

    }

托管豆

@ManagedBean
@ViewScoped
public class UnidadeEscolarMB {
    private UnidadeEscolar bean;
    private GenericDAO<UnidadeEscolar> dao;
    private List<UnidadeEscolar> unidades = null;


    /** insere uma nova unidade escolar */
    public void prepareCreate(){
        bean = new UnidadeEscolar();        
    }

    /** retorna o objeto */
    public UnidadeEscolar getBean() {
        return bean;
    }

    /** define o objeto */
    public void setBean(UnidadeEscolar bean) {
        this.bean = bean;
    }

    //enum values
    public EstadosDoBrasil[] getUF(){
        return EstadosDoBrasil.values();
    }
}

Xhtml

<p:outputLabel value="U.F"/>
<p:selectOneMenu value="#{unidadeEscolarMB.bean.endereco.uf}">
      <f:selectItems value="#{unidadeEscolarMB.UF}" var="uf"
                     itemLabel="#{uf}" itemValue="#{uf}"/>                  
</p:selectOneMenu>

例外

1100: /unidade_escolar/create.xhtml @75,80 value="#{unidadeEscolarMB.bean.endereco.uf}": Target Unreachable, 'bean' returned null
javax.el.PropertyNotFoundException: /unidade_escolar/create.xhtml @75,80 value="#{unidadeEscolarMB.bean.endereco.uf}": Target Unreachable, 'bean' returned null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at org.primefaces.renderkit.InputRenderer.findImplicitConverter(InputRenderer.java:172)
    at org.primefaces.renderkit.InputRenderer.getOptionAsString(InputRenderer.java:158)
    at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeOption(SelectOneMenuRenderer.java:345)
    at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeSelectItems(SelectOneMenuRenderer.java:331)
    at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeInput(SelectOneMenuRenderer.java:114)
    at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:91)
    at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:65)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:92)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
    at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
    at org.primefaces.component.dialog.DialogRenderer.encodeContent(DialogRenderer.java:184)
    at org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.java:113)
    at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.java:47)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:74)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:72)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
    at org.primefaces.component.dialog.DialogRenderer.encodeContent(DialogRenderer.java:184)
    at org.primefaces.component.dialog.DialogRenderer.encodeMarkup(DialogRenderer.java:113)
    at org.primefaces.component.dialog.DialogRenderer.encodeEnd(DialogRenderer.java:47)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:74)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:72)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
    at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:51)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'bean' returned null
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:122)
    at org.apache.el.parser.AstValue.getType(AstValue.java:56)
    at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:171)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    ... 68 more
4

0 回答 0