0

我正在做一个小项目,在一切正常工作后突然我开始得到一个javax.el.PropertyNotFoundException:,但我仍然不知道是什么导致了问题,我对上一个工作版本之间的代码所做的唯一更改是一个新的 xhtml,文档,称为 categoryController。我真的不知道发生了什么,也不知道如何解决。有谁知道如何解决这个问题?

我做了一些研究,发现添加 beans.xml,但是,在问题发生之前我确实有 beans.xml。这是 beans.xml 的内容:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

这是 categoryController bean:

@Named
@RequestScoped
public class CategoryController {

    @EJB
    private CategoryEJB categoryEjb;

    private Category category = new Category();
    private List<Category> categories = new ArrayList<Category>();

    // ------------------------------------------------------------- Constructor

    public CategoryController() {
    }

    // -------------------------------------------------------- Business Methods

    public String doCreateCategory()
    {
        category = categoryEjb.createCategory(category);
        categories = categoryEjb.findAllCategory();
        return "listCategory?faces-redirect=true";
    }  

这是被调用的形式:

 <h:form>
                <h1><h:outputText value="Create New Catergory"/></h1>
                <h:panelGrid columns="2">                    
                    <h:outputLabel value="Name:" for="name" />
                    <h:inputText id="name" value="#{categoryController.category.name}" title="Name" />
                    <h:outputLabel value="Description:" for="description" />
                    <h:inputText id="description" value="#{categoryController.category.description}" title="Description" />                    
                </h:panelGrid>
                <h:commandButton value="Create Category" action="#{categoryController.doCreateCategory()}"/>                
            </h:form>

这是我得到的完整堆栈:

javax.el.PropertyNotFoundException: /product/createCategory.xhtml @15,103 value="#{categoryController.category.name}": Target Unreachable, identifier 'categoryController' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
    at javax.faces.component.UIInput.validate(UIInput.java:960)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
    at javax.faces.component.UIInput.processValidators(UIInput.java:698)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
    at javax.faces.component.UIForm.processValidators(UIForm.java:253)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    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.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    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)

编辑:

@Entity
@NamedQueries({
    @NamedQuery(name= "findAllCategory", query="SELECT c FROM Category c")   
})
public class Category implements Serializable
{
    private static final long serialVersionUID = 1L;

    @Id @GeneratedValue(strategy= GenerationType.AUTO)
    private int category_id;
    private String name;
    private String description;
    @OneToMany(mappedBy = "category_fk")
    private List<Product> product_fk;

    // ------------------------------------------------------------- Constructor

    public Category() {
    }

    public Category(String name, String description, List<Product> product_fk) {
        this.name = name;
        this.description = description;
        this.product_fk = product_fk;
    }    

    // ---------------------------------------------------- Getters and Setters

    public int getCategory_id() {
        return category_id;
    }

    public void setCategory_id(int category_id) {
        this.category_id = category_id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<Product> getProduct_fk() {
        return product_fk;
    }

    public void setProduct_fk(List<Product> product_fk) {
        this.product_fk = product_fk;
    }    
4

1 回答 1

0

例外情况是,找不到您的 bean 的属性。您的 bean 中的类别和类别对象中的字段名称是否具有正确且可见的 getter/setter 方法?

编辑:

我刚刚看到,PropertyNotFoundException 确实引用了 bean 本身,而不是 bean 中的字段。你的豆子有名字吗?您的 @Named 应该类似于在上下文中找到的 @Named("categoryController") 。

于 2012-11-07T19:28:21.777 回答