gpt4 book ai didi

jsf - 目标无法到达,标识符解析为空

转载 作者:行者123 更新时间:2023-12-04 16:46:21 25 4
gpt4 key购买 nike

我在使用 JSF 2.2 中的一个简单 Web 应用程序时遇到问题,我的托管 bean 没有解决,我得到了这个错误:

 /greeting.xhtml @21,66 date="#{dukesBDay.yourBD}": Target Unreachable, identifier 'dukesBDay' resolved to null

这是我的托管 bean:

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

@ManagedBean
@SessionScoped
public class DukesBDay {


@EJB
private DukesBirthDayBean dukesBirthdayBean;

这是我的 greeting.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:fc="http://java.sun.com/jsf/composite/components">

<h:head>
<title>First Cup Greeting Page</title>
</h:head>

<h:form>
<h2>
<h:outputText value="#{bundle.Welcome}"/>
</h2>
<h:outputText value="#{bundle.DukeIs} "/>
<h:outputText value="#{dukesBDay.age} #{bundle.YearsOldToday}"/>
<p/>
<h:outputText value="#{bundle.Instructions}"/>
<p/>
<h:outputText value="#{bundle.YourBD} "/>
<fc:inputDate id="userBirthday" date="#{dukesBDay.yourBD}" />
<h:outputText value=" #{bundle.Pattern}"/>
<p/>
<h:commandButton value="#{bundle.Submit}"
action="#{dukesBDay.processBirthday}"/>
<p/>
<h:message for="userBirthday" style="color:red"/>
</h:form>

这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>greeting.xhtml</welcome-file>
</welcome-file-list>
</web-app>

我尝试将名称属性添加到@ManagedBean:

package firstcup.web;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="dukesBDay")
@SessionScoped
public class DukesBDay {

但是还是不行,还是一样的错误。

我尝试在我的 faces-config 中映射托管 bean:

 <managed-bean>
<managed-bean-name>dukesBDay</managed-bean-name>
<managed-bean-class>firstcup.web.DukesBDay</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

但是我得到这个错误:

Unable to create managed bean dukesBDay. The following problems were found: - Bean or property class firstcup.web.DukesBDay for managed bean dukesBDay cannot be found

为什么我的 DukesBDay 没有解决?怎么了?

谢谢

最佳答案

我解决了重新启动 NetBeans 和 GlassFish Server 的问题。

我没有给@ManagedBean 添加name 属性:

package firstcup.web;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class DukesBDay {

一切正常,所以没有必要(根据命名约定,您可以使用类的非大写短名称来引用该 bean)

关于jsf - 目标无法到达,标识符解析为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28138685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com