0

I'm trying to develop a hangman game.

Mainly I have an xhtml file which calls a jugadorController.preparePartida();

the code is:

public String preparePartida() {

try {
    Map<String, Object> sesionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
    Integer id = (Integer) sesionMap.get("id_jugador");

    Jugador jugador = getFacade().find(id);

    Partida p = new Partida();
    p.setIdJugador(jugador);
    PartidaController partida = new PartidaController();

    return partida.createPartida(p);


} catch (Exception e) {
    JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
    return null;
}

partida.CreatePartida code is:

public String createPartida(Partida partida) {
        try {
            current=partida;
            ejbFacade.create(current);
                  JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PartidaCreated"));
            return "jugar";
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

The problem is when create(current) is invoked. It doesn't work because ejbFacade is null.

How should I declare the classes correctly for this to run? Am I not calling some method?

Thank you!!!

PS. A desesperate computer science student who has no idea about Java... =)

SJuan76
  • 24,532
  • 6
  • 47
  • 87
dak
  • 199
  • 1
  • 5
  • 18
  • 1
    And where do you define `ejbFacade` and assign a value? that is the important part of the code (for solvig this issue). – SJuan76 May 30 '13 at 14:22
  • 1
    Not knowing anything about Java and working with JSF + EJB is not the best idea... we cannot know why `ejbFacade` is null because you did not share the declaration. – home May 30 '13 at 14:22
  • Well... I have a postgres databas... First I generate the .java classes from the database tables (I'm working with Netbeans). – dak May 30 '13 at 14:46
  • Sorry.. pressed enter ( XD ) Once the entity classes are generated I generate ClassController and ClassFacade classes... Netbeans also autogenerates these classes... Jugador controller has a private DBClasses.JugadorFacade ejbFacade and PartidaController has another one private DBClasses.PartidaFacade ejbFacade; – dak May 30 '13 at 14:49
  • SJuan76.. the problem is that I'm assigning the value and I have no idea where should I do that... XD ejbFacade is who calls the EntityManager of the class to put everything int the DB. xhtml files normally calls methods that I can't see and they do everything like magic... If you know where should I put those declarations it would be great. – dak May 30 '13 at 15:04
  • Well I Changed some things and it works... I've put the sessionMap in the other method and changed the call in the xhtml file and it works. =) – dak May 30 '13 at 15:08

0 Answers0