简体   繁体   English

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

[英]JSF : PropertyNotFoundException The class '' does not have the property ''

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 AND 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 : Page 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). 如您所见,Bean已解析,甚至解析了createclient()方法(我试图在没有其余代码的情况下测试它)。 The problem is just about attributes... 问题只是属性......

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>

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一起使用,这些bean本身不应该没有问题。

  1. You are using javax.faces.bean.SessionScoped and javax.faces.bean.ManagedBean but instead you should use javax.enterprise.context.SessionScoped and javax.annotation.ManagedBean or even javax.inject.Named instead of ManagedBean . 您正在使用javax.faces.bean.SessionScopedjavax.faces.bean.ManagedBean但您应该使用javax.enterprise.context.SessionScopedjavax.annotation.ManagedBean或甚至javax.inject.Named而不是ManagedBean Have a look at this question to get details about the differences. 请查看此问题以获取有关差异的详细信息。

  2. The file manage-beans.xml you have created has content which normally belongs to the faces-config.xml but which is anyway obsolete because the declaration in XML is an alternative to the declaration via annotations. 您创建的文件manage-beans.xml具有通常属于faces-config.xml内容,但无论如何都是过时的,因为XML中的声明是通过注释声明的替代方法。 You don't need both. 你不需要两者。 You can delete the manage-beans.xml and the reference in the web.xml . 您可以删除web.xmlmanage-beans.xml和引用。 If you want to use such XML declarations you can yust put them in the faces-config.xml . 如果你想使用这样的XML声明,你可以将它们放在faces-config.xml

  3. Your web.xml contains facelets.SKIP_COMMENTS which should be replaced with javax.faces.FACELETS_SKIP_COMMENTS . 您的web.xml包含facelets.SKIP_COMMENTS ,应该用javax.faces.FACELETS_SKIP_COMMENTS替换。

  4. Your project is missing a beans.xml . 您的项目缺少beans.xml You wrote in a comment that you already created one, anyway here is a reference how it should look like: 你在评论中写道,你已经创建了一个,无论如何这里是一个参考它应该是什么样子:

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: 也可以看看:

To enable CDI in JSF2.0 , you need to use beans.xml or faces-config.xml to define your managed beans. 要在JSF2.0中启用CDI,您需要使用beans.xml或faces-config.xml来定义托管bean。 It is recommended to use a seperate file for configuring the beans since faces-config.xml will have application specific configuration. 建议使用单独的文件来配置bean,因为faces-config.xml将具有特定于应用程序的配置。 Please read this link to gain more understanding on how CDI works. 请阅读此链接以更多地了解CDI的工作原理。 Please note that CDI works based on the JAVA EE version. 请注意,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,并确保正确加载了类和配置文件

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. 在您关注所有其他建议后,请更改此设置,并且您的例外情况应该消失。

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. 因此,当我编译和重新部署时,它为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类&#39;java.lang.String&#39;没有属性&#39;user&#39; - org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'user' org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类&#39;java.lang.String&#39;没有属性&#39;id&#39; - org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.lang.String' does not have the property 'id' JSF AJAX-类没有属性 - JSF AJAX - Class doesn't have property JSF + Hibernate serverError:类javax.el.PropertyNotFoundException - JSF + Hibernate serverError: class javax.el.PropertyNotFoundException JSF 错误:class 'java.lang.String' 没有属性 'lista' - JSF error: The class 'java.lang.String' does not have the property 'lista' Spring的类必须是AutoWire中的一个属性吗? - Spring does class have to be component to AutoWire a property in it? Spring webflow PropertyNotFoundException:找不到属性 - Spring webflow PropertyNotFoundException: Property not found 在没有名为“类型”的属性的类中,我得到org.hibernate.PropertyNotFoundException:在类中找不到属性类型的设置方法 - In class without a property called “type” I get org.hibernate.PropertyNotFoundException: Could not find a setter for property type in class PropertyNotFoundException:在类型X上找不到属性“ X” - PropertyNotFoundException: Property 'X' not found on type X javax.el.PropertyNotFoundException:找不到属性[id] - javax.el.PropertyNotFoundException: Property [id] not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM