samedi 4 avril 2015

spring pass the object to the jsf view

I have a class that is mostly populated with the data from Facebook, however missing two attributes that have to be filled from coming from a form data.


This is the form: central/cadastro.xhtml



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb" xmlns:h="http://ift.tt/HjFrZb"
xmlns:f="http://ift.tt/19DXC4H"
xmlns:c="http://ift.tt/1kyxZva">

<h:body>
<h:graphicImage value="http://ift.tt/1bYd7fs" /> 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 through ModelAndView the spring * * method, passing an object of typeUsuarioFacebook with the name of 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;
}
}


the return is a java.lang.NullPointerException sincecommandButton does not pass the object usuario to thepersist (), why?


Both UsuarioFacebookDAO as UsuarioFacebookare noted asManagedBean`.


Aucun commentaire:

Enregistrer un commentaire