Reputation: 326
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>
Upvotes: 1
Views: 20113
Reputation: 1
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.
Upvotes: 0
Reputation: 23381
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.
Upvotes: 0
Reputation: 13857
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.
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.
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
.
Your web.xml contains facelets.SKIP_COMMENTS
which should be replaced with javax.faces.FACELETS_SKIP_COMMENTS
.
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:
Upvotes: 3
Reputation: 12890
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
Upvotes: 0