Passing Spring object to JSF

3

Well, I have a class that is almost all populated with Facebook data, but there are two missing attributes that have to be populated from data coming from a form.

Here is the form: central/cadastro.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core"
  xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

<h:body> 
    <h:graphicImage value="https://graph.facebook.com/${usuario.id}/picture" /> Olá, ${usuario.firstName} ${usuario.lastName}
    <h:form id="formCadastro" prependId="false"> 
        <h:panelGrid columns="2">

            Login: <h:inputText label="Login" value="#{usuarioFacebook.userid}" /> 
            Senha: <h:inputSecret label="Senha" value="#{usuarioFacebook.password}" />
            <h:commandButton value="Salvar" action="#{usuarioFacebookDAO.persist(usuario)}"/>
        </h:panelGrid>
    </h:form> 
</h:body> 
</html>

This form is displayed by the method ModelAndView of spring , passing an object of type UsuarioFacebook with the name usuario :

@RequestMapping("/loginfbresponse")
public ModelAndView logarComFacebook(String code) throws MalformedURLException, IOException{

  UsuarioFacebook userFB = loginFacebook.obterUsuarioFacebook(code);
    System.out.println("Buscando email " + userFB.getEmail() + " no banco...");
      UsuarioFacebook userFBDB = usuarioFacebookDAO.find(userFB.getId());
      if(userFBDB == null){
        if(userFB.getVerified()){
          //usuarioFacebookDAO.persist(userFB);
          System.out.println("Usuário " + userFB.getEmail() + " foi direcionado para cadastro.");

          ModelAndView mv = new ModelAndView("central/cadastro");
          mv.addObject("usuario", userFB);
          return mv;
        } else {
          System.out.println("Usuário " + userFB.getEmail() + " não é uma conta ativa.");
          ModelAndView mv = new ModelAndView("central/containvalida");
          return mv;
        }                    
      } else {
        System.out.println("Usuário " + userFB.getEmail() + " foi encontrado!");
        ModelAndView mv = new ModelAndView("central/home");
        mv.addObject("usuario", userFBDB);
        return mv;
      }
}

return is a java.lang.NullPointerException because commandButton does not pass the usuario object to the persist() method, why?

Both UsuarioFacebookDAO and UsuarioFacebook are written as ManagedBean .

    
asked by anonymous 05.04.2015 / 04:10

0 answers