目标无法访问'客户端'返回null

时间:2014-07-10 14:20:07

标签: hibernate jsf

我已经创建了一个添加方法,我使用了jsf和hibarnate框架,但是出现了一个值得注意的例外,她阻止了我。

这是我的班级豆类

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;
    }


}

她的观点

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

错误:

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

我知道还有很多其他问题都有相同的标题,但没有一个有效.plz plz帮帮我,我开始放手了我

1 个答案:

答案 0 :(得分:0)

@AutoWired不会将spring bean注入jsf bean;他们处于两种不同的环境中。

只有当@Autowired也是Spring MVC管理的bean时,Spring才能使用ClientBeanManger注入bean。从你的问题编写方式和评论来看,我认为你需要探索连接Spring bean和JSF bean的基础知识。

看看以下