1

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.

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 :

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

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 :

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

<?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>
strategesim
  • 197
  • 2
  • 2
  • 12
  • Can you add @ManagedBean(name="clientController") in your class and check? – Keerthivasan Dec 27 '13 at 10:19
  • @Octopus Good idea, I just tried, but no, same problem. I do really think that the problem is not in bean name resolution. Perhaps a configuration problem in an other file ? – strategesim Dec 27 '13 at 10:27
  • Do you have beans.xml or faces-config.xml? – Keerthivasan Dec 27 '13 at 10:28
  • No, and I think that is the problem, but I don't know what to put on it, where to put it. The example where I found this code (http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/) does provide some but doesn't mention the controller in it – strategesim Dec 27 '13 at 10:37
  • Check out this link -http://www.mkyong.com/jsf2/configure-managed-beans-in-jsf-2-0/. You will know how and where to define your managed beans – Keerthivasan Dec 27 '13 at 10:47
  • Ah and I have something strange when I deploy... the JSF1063 error : Setting non-serializable attribute value into HttpSession (key: clientController, value class: controllers.ClientController). – strategesim Dec 27 '13 at 11:23
  • Then, your ClientController class doesn't seem to implement Serializable?? How is that? – Keerthivasan Dec 27 '13 at 11:26
  • You see it in the code it does implements Serializable... I tried to restart my glassfish and redeploy the project from scratch but it still does not recognize the Serializable implementation !!! – strategesim Dec 27 '13 at 11:30
  • Can you add the stacktrace to your question? – Jorge Campos Dec 27 '13 at 13:46

4 Answers4

3

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.

  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. 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. You don't need both. You can delete the manage-beans.xml and 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_COMMENTS which 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:

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:

Community
  • 1
  • 1
unwichtich
  • 13,143
  • 2
  • 46
  • 60
  • Thanks for your complete answer. That does really help me, I finally loaded the page with a tear rolling :) But now the bean is juste unreachable : identifier 'clientController' resolved to null. btw I'm trying to fix it (I opted for a @Named bean, looking into your links about any other configuration in that case) – strategesim Dec 27 '13 at 13:55
0

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 link to gain more understanding on how CDI works. Please note that CDI works based on the JAVA EE version.

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

Keerthivasan
  • 12,040
  • 2
  • 26
  • 49
0

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

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

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

Jorge Campos
  • 20,662
  • 7
  • 51
  • 77
  • Hum I don't have it in my project... Perhaps a IDE config problem ? Anyway thanks for trying to help me :) – strategesim Dec 27 '13 at 13:57
  • Well if you copy/pasted your code it is on your index.xhtml and normally it is the cause for `PropertyNotFoundException`. But if you say that isn't, you should revise all other `value` attribute to see if it is correct mapped. – Jorge Campos Dec 27 '13 at 14:05
  • Oh you're right, seems that I made a mistake when editing the pasted code to format my post (first post here, what a newbie) – strategesim Dec 27 '13 at 14:10
0

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.

Arora
  • 1