0

I have created a method to add and I used the jsf and hibarnate framwork but a notable exception appear and she blocked me.

this my class beans

package controller;

import java.io.Serializable;
import javax.faces.bean.RequestScoped; 
import org.springframework.beans.factory.annotation.Autowired;
import model.Client;
import javax.faces.bean.ManagedBean;
import service.ClientService;

@ManagedBean(name="clientBean")
@RequestScoped
public class ClientBeanManger implements Serializable {

    private static final long serialVersionUID = 1L;
    private static final String SUCCESS = "success";
    private static final String ERROR   = "error";

    //Spring User Service is injected...
    @Autowired
    ClientService clientService;
    private Client client;




    public Client getClient() {
        return client;
    }


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


    public ClientBeanManger() {

    }

    private int idClient;
    private String nomClient;
    private String adresseClient;
    private String telephoneClient;
    private String mailClient; 



    // Add client @return String - Response Message

    public void addClient(Client client) {
        client.setIdClient(idClient);
        client.setNomClient(nomClient);
        client.setAdresseClient(adresseClient);
        client.setTelephoneClient(telephoneClient);
        client.setMailClient(mailClient);
        clientService.add(client);          
    }


    //Getter and  setter 
    public ClientService getClientService() {
        return clientService;
    }

    public void setClientService(ClientService clientService) {
        this.clientService = clientService;
    }

    public int getIdClient() {
        return idClient;
    }

    public void setIdClient(int idClient) {
        this.idClient = idClient;
    }

    public String getNomClient() {
        return nomClient;
    }

    public void setNomClient(String nomClient) {
        this.nomClient = nomClient;
    }

    public String getAdresseClient() {
        return adresseClient;
    }

    public void setAdresseClient(String adresseClient) {
        this.adresseClient = adresseClient;
    }

    public String getTelephoneClient() {
        return telephoneClient;
    }

    public void setTelephoneClient(String telephoneClient) {
        this.telephoneClient = telephoneClient;
    }

    public String getMailClient() {
        return mailClient;
    }

    public void setMailClient(String mailClient) {
        this.mailClient = mailClient;
    }


}

her my view

 <html xmlns="http://www.w3.org/1999/xhtml"
         xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
         xmlns:p="http://primefaces.org/ui">
     <h:body>
         <h:form  action="" method="post">
          <table border="1">
           <tr>
            <td><h:outputLabel value="Id :"/></td>
            <td><h:inputText id="id" value="#{clientBean.idClient}"/>  
            </td>
           </tr>
           <tr>
            <td><h:outputLabel for="name" value="Name :" /></td>
            <td><h:inputText id="name" value="#{clientBean.nomClient}"/>

            </td>
           </tr>
            <tr>
            <td><h:outputLabel for="adresse" value="Adresse :" /></td>
            <td><h:inputText id="adresse" value="#{clientBean.adresseClient}"/>
            </td>
           </tr>
            <tr>
            <td><h:outputLabel for="telephone" value="Telephone :" /></td>
            <td><h:inputText id="telephone" value="#{clientBean.telephoneClient}"/>
           </td>
           </tr>
              <tr>
            <td><h:outputLabel for="mail" value="Mail :" /></td>
            <td><h:inputText id="mail" value="#{clientBean.mailClient}"/>
           </td>
           </tr>
             <tr>
           <td><h:commandButton id="addclient" value="Add" action="#{clientBean.addClient}"/></td>
            <td><h:commandButton id="reset" value="Lister"  action="Submit"/></td> 
           </tr>
          </table>
         </h:form>
    </h:body>
    </html>

the error :

Etat HTTP 500 - javax.el.PropertyNotFoundException: /pages/index.xhtml @35,97 action="#{clientBean.client.addClient}": Target Unreachable, 'client' returned null

I know there are many other questions with the same title, but none of them worked.plz plz help me, I started to let go of me

user3766709
  • 15
  • 2
  • 6

1 Answers1

0

@AutoWired will not inject a spring bean into a jsf bean; they're in two different contexts.

Spring will be able to inject the bean using @Autowired only if the ClientBeanManger is also a Spring MVC-managed bean. From the way your question is written and the comments, It looks to me like you need to explore the basics of wiring Spring beans and JSF beans.

Have a look at the following

Community
  • 1
  • 1
kolossus
  • 19,953
  • 3
  • 45
  • 94