Java JSF:PropertyNotFoundException 类 '' 没有属性 ''

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20798696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:24:54  来源:igfitidea点击:

JSF : PropertyNotFoundException The class '' does not have the property ''

javajsfel

提问by strategesim

Two days I'm looking for a solution to that basic problem. And YES I do have GETTER AND SETTER, and YES I really think that the convention is OK.

这两天我正在寻找解决这个基本问题的方法。是的,我确实有 GETTER 和 SETTER,是的,我真的认为约定是可以的。

Here is the code :

这是代码:

Bean :

豆角,扁豆 :

@Named
@SessionScoped
public class ClientController implements Serializable {

@Inject
private ClientService das;
private List<Client> clientsList;
public void setClientsList(List<Client> clientsList) {
    this.clientsList = clientsList;
}

private Client client = new Client();


public Client getClient() {
    return client;
}

public void setClient(Client client) {
    this.client = client;
}

public void createclient(ActionEvent actionEvent) {
    das.create(client);
}

public List<Client> getClientsList() {
    clientsList = das.findByNativeQuery(Client.ALL);
    return clientsList;
}

}

Page index.xhtml :

页面 index.xhtml :

<ui:composition template="/templates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">

<ui:define name="content">

    <h:form>
        <p:panel header="Créer un Client">
            <h:outputText value="Prénom : "></h:outputText>
            <p:inputText id="clientName" value="#{clientController.client.name}" required="true"
                requiredMessage="Entrez votre prénom" message="fc">
                <f:validateLength minimum="2" />
            </p:inputText>
            <h:outputText value="Nom : "></h:outputText>
            <p:inputText id="clientLastName" value="#{clientController.client.lastName}"
                required="true" requiredMessage="Entrez votre nom"   message="fc">
                <f:validateLength minimum="2" />
            </p:inputText>
        </p:panel>
        <p:commandButton value="Submit"         
            actionListener="#{clientController.createclient}" />
    </h:form>
</ui:define>
</ui:composition>

Error :

错误 :

/index.xhtml @14,57 value="#{clientController.client.name}": The class 'controllers.ClientController' does not have the property 'client'.

As you can see, the Bean is resolved, and even the createclient() method is resolved (I tried to test it without the rest of the code). The problem is just about attributes...

如您所见,Bean 已解析,甚至 createclient() 方法也已解析(我尝试在没有其余代码的情况下对其进行测试)。问题只是关于属性......

Please help ? I'm sure it's a stupid problem, but sometimes we just need an other point of view

请帮忙 ?我敢肯定这是一个愚蠢的问题,但有时我们只需要另一种观点

EDIT:

编辑:

WEB-INF/web.xml :

WEB-INF/web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Bourse</display-name>

<!-- Current project stage. When it is set to 'Development' Primefaces give 
    a lot of debug information on the screen. -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<context-param>
    <param-name>facelets.SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>

<welcome-file-list>
    <welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>

<!-- Staring JSF -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- JSF URL mapping -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/manage-beans.xml</param-value>
</context-param>
</web-app>

WEB-INF/manage-beans.xml :

WEB-INF/manage-beans.xml :

<?xml version="1.0" encoding="UTF-8"?>
 <faces-config 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/web-facesconfig_2_0.xsd"
    version="2.0">
    <managed-bean>
        <managed-bean-name>clientController</managed-bean-name>
        <managed-bean-class>controllers.ClientController</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
 </faces-config>

采纳答案by unwichtich

I checked your code and there are several problems but I'm not sure which one is causing YOUR problem because i commented out the database stuff to make it work quickly.

我检查了你的代码,有几个问题,但我不确定是哪一个导致了你的问题,因为我注释掉了数据库内容以使其快速工作。

I guess the main problem is that you try to use CDI together with JSF managed beans which is not supposed to work without problems.

我想主要问题是您尝试将 CDI 与 JSF 托管 bean 一起使用,这不应该没有问题。

  1. You are using javax.faces.bean.SessionScopedand javax.faces.bean.ManagedBeanbut instead you should use javax.enterprise.context.SessionScopedand javax.annotation.ManagedBeanor even javax.inject.Namedinstead of ManagedBean. Have a look at this questionto get details about the differences.

  2. The file manage-beans.xmlyou have created has content which normally belongs to the faces-config.xmlbut which is anyway obsolete because the declaration in XML is an alternative to the declaration via annotations. You don't need both. You can delete the manage-beans.xmland the reference in the web.xml. If you want to use such XML declarations you can yust put them in the faces-config.xml.

  3. Your web.xml contains facelets.SKIP_COMMENTSwhich should be replaced with javax.faces.FACELETS_SKIP_COMMENTS.

  4. Your project is missing a beans.xml. You wrote in a comment that you already created one, anyway here is a reference how it should look like:

  1. 您正在使用javax.faces.bean.SessionScopedandjavax.faces.bean.ManagedBean但您应该使用javax.enterprise.context.SessionScopedandjavax.annotation.ManagedBean甚至javax.inject.Named代替ManagedBean。查看此问题以获取有关差异的详细信息。

  2. 该文件manage-beans.xml已创建具有通常属于内容faces-config.xml但无论如何已经过时,因为在XML声明是通过注解声明的替代品。你不需要两者。您可以删除manage-beans.xml和 中的引用web.xml。如果您想使用这样的 XML 声明,您只需将它们放在faces-config.xml.

  3. 您的 web.xml 包含facelets.SKIP_COMMENTS应替换为javax.faces.FACELETS_SKIP_COMMENTS.

  4. 您的项目缺少beans.xml. 你在评论中写道你已经创建了一个,无论如何这里是一个参考它应该是什么样子:

Example:

例子:

<?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>

See also:

也可以看看:

回答by Keerthivasan

To enable CDI in JSF2.0 , you need to use beans.xml or faces-config.xml to define your managed beans. It is recommended to use a seperate file for configuring the beans since faces-config.xml will have application specific configuration. Please read this linkto gain more understanding on how CDI works. Please note that CDI works based on the JAVA EE version.

要在 JSF2.0 中启用 CDI,您需要使用 beans.xml 或 faces-config.xml 来定义您的托管 bean。建议使用单独的文件来配置 bean,因为 faces-config.xml 将具有特定于应用程序的配置。请阅读此链接以进一步了解 CDI 的工作原理。请注意,CDI 基于 JAVA EE 版本工作。

Update:

更新:

You need to check whether you are naming your beans correctly everywhere in your xhtml page and make sure your class and configuration files are properly loaded

您需要检查是否在 xhtml 页面的任何地方都正确命名了 bean,并确保正确加载了类和配置文件

回答by Jorge Campos

Besides all other problems the guys said on previous answers that you have to check, you just have a EL problem:

除了这些人在之前的答案中说的所有其他问题你必须检查,你只是有一个 EL 问题:

 value="# {clientController.client.lastName}"
         ^here this is not valid for EL

After you follow all others suggestions change this and your exception should disapear.

在您遵循所有其他建议后,请更改此设置,您的异常应该会消失。

回答by Arora

In my case, i just changed the name of variable and the target folder was not reflecting the changes. So when I compile and redeploy it worked for me.

就我而言,我只是更改了变量的名称,目标文件夹没有反映更改。因此,当我编译和重新部署时,它对我有用。