JSF错误:无法到达目标,标识符“ bean”解析为空

时间:2018-12-27 23:54:07

标签: java jsf java-ee glassfish cdi

我正在Java EE中使用CDI,但是它似乎不起作用。

我有一个非常简单的示例,其中包含2个文本字段。输入名称并提交时,输入的名称应显示在下一页。

enter image description here

但是我收到以下错误:

HTTP Status 500 - Internal Server Error

javax.servlet.ServletException: /index.xhtml @12,72 value="#{userBean.firstName}": Target Unreachable, identifier 'userBean' resolved to null

javax.el.PropertyNotFoundException: /index.xhtml @12,72 value="#{userBean.firstName}": Target Unreachable, identifier 'userBean' resolved to null

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'userBean' resolved to null

这些是我的3个文件:

index.xhtml

<h:form>
    <h:panelGrid columns="2">
        <h:outputLabel value="First name" for="firstName"/>
        <h:inputText id="firstName" value="#{userBean.firstName}"/>


        <h:outputLabel value="Last name" for="lastName"/>
        <h:inputText id="lastName" value="#{userBean.lastName}"/>
      <h:commandButton action="result" value="send"/>
    </h:panelGrid>
</h:form>

result.xhtml

First name: #{userBean.firstName}
Last name: #{userBean.lastName}

UserBean.java

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class UserBean {

    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

}

0 个答案:

没有答案