I have a view that display a list of users, from this view I can go to another view of \"details\" of any selected user. In the details view I need to select some values fro
Bad getter!
public Usuario getU() {
getParam();
return u;
}
The getter above is a very bad idea. You've said it yourself that the variable makes it into the usuario
backing bean(this I doubt). It is just plain wrong to perform business logic inside a getter because of inconsistencies (like you're experiencing) and the fact that the getter is called multiple times during a request. There are more elegant and cleaner ways to pass and initialise parameters between JSF pages.
private Usuario u=new Usuario();
is also a bad idea. Why is this necessary when you have
this.setU(controlador.getUser(param));
All that should happen inside your @PostConstructor
@PostConstruct
public void init() {
controlador=new usuarioController();
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
//Obtener parametros del request
Map<String, String> parameterMap = (Map<String, String>) externalContext.getRequestParameterMap();
Long param = Long.valueOf(parameterMap.get("id_usuario"));
System.out.println(param);
this.setU(controlador.getUser(param));
}
The getter should just be plain
public Usuario getU() {
return u;
}
The cause of this error is that parameterMap.get("id_usuario")
is null. You should investigate how you pass this parameter from the UI to the backing bean.