3
Well, I have a class that is almost entirely populated with Facebook data, but two attributes are missing that have to be filled 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 through the method ModelAndView
of spring, passing an object of the type UsuarioFacebook
by 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
for the commandButton
does not pass the object usuario
for the method persist()
, why?
Both the UsuarioFacebookDAO
as to the UsuarioFacebook
are noted as ManagedBean
.
Dude, in the login form, you already tried to use userFacebookDAO.persist(userFacebook) instead of userFacebookDAO.persist(user)?
– George Moura
If I persist the userFacebook the data will not be complete because userFacebook would be a JSF object. I solved the problem by leaving aside the use of JSF because it doesn’t go very well with Spring =)
– SoabTI