目标无法到达,标识符"demoBean"解析为空 [英] Target Unreachable, identifier 'demoBean' resolved to null

查看:93
本文介绍了目标无法到达,标识符"demoBean"解析为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在NetBeans 7.0上使用JSF开发Web应用程序.我创建了2个页面:一个用于输入人员姓名,另一个用于显示该姓名.我正在将Java bean与get和set方法一起使用.

I am developing a web application using JSF on Netbeans 7.0. I have created 2 pages: one for entering persons name and other to display that name. I am using a java bean with get and set methods.

在首页上提交代码时,我得到了一个错误.

I get an error when I submit my form on first page the code.

这是我接受姓名的第一页index.xhtml

This is my first page index.xhtml to accept name:

<h:form>
    Enter your Name : <h:inputText value="#{demoBean.name}" required="true"/>
    <br/> <h:commandButton value="Submit" action="welcome.xhtml"/>    
</h:form>

这是另一页显示名称的页面welcome.xhtml

This is the other page welcome.xhtml to display the name:

<h:body>
    Hello #{demoBean.name}
</h:body>

这是托管bean demoBean.java:

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 

@ManagedBean()
@SessionScoped

public class demoBean {
    private String name;

    public String getName() {
        return name;
    }

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

这是我提交拳头页面时遇到的错误:

This is the error which I got when I submit the fist page:

/index.xhtml @ 10,86 value =#{demoBean.name}":无法到达目标,标识符为'demoBean'
解析为空

/index.xhtml @10,86 value="#{demoBean.name}": Target Unreachable, identifier 'demoBean'
resolved to null

推荐答案

JSP框架希望您的bean类名称符合Java命名约定,即为"CamelCased"(例如DemoBean),在这种情况下,它将假定将在JSP中使用默认名称来引用该bean,该默认名称是通过将bean名称的第一个字符转换为小写字母(demoBean)形成的.

The JSP framework expects your bean class name to conform to the Java naming conventions, i.e. be "CamelCased" (e.g. DemoBean), in which case it will assume the bean will be referenced in the JSP by the default name formed by converting the first character of the bean name to lower case (demoBean).

由于偏离了框架的期望,因此需要在@ManagedBean批注中或在可选的faces-config.xml文件中指定在JSP中引用bean的名称.

As you have deviated from the framework's expectations, you need to indicate the name by which you refer to your bean in the JSPs, either by specifying it in the @ManagedBean annotation or in the optional faces-config.xml file.

这篇关于目标无法到达,标识符"demoBean"解析为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆