0

I'm trying to access an object in my sessioncontroller (sessionscoped bean) from a managedbean. The sessionobject gets created when you log in. Then when I try to persist from the requestscoped bean and I need the login-object from the sessioncontroller but when I debug it's always null.

Bean

@ManagedBean
@ViewScoped
// ??? @RequestScoped
public class BoekingController {

@Inject
private ZoekService zoekService;
@Inject
private BetaalwijzeService betaalwijzeService;
@EJB
private transient BoekingService boekingService;
@ManagedProperty("#{sessionController}")
private SessionController sessionController;

public void init() {
    if (betaalwijzeId > 0) {
        betaalwijze = betaalwijzeService.findToegestandBetaalwijze(betaalwijzeId);
    }

    reis = zoekService.findReis(reisId);

    if (aantalPersonen > 0) {
        instellenBoeking(aantalPersonen, betaalwijze, new Klant(1, "Test", "test@test.be", "test"), reis);
    }
}

As you can see I have hardcoded the object myself and persistence works, I just can't get the variable from the sessionController posted below.

SessionController

@SessionScoped
@Named(value = "sessionController")
public class SessionController implements Serializable{
Klant klant;

public Klant getKlant() {
    return klant;
}
public void setKlant(Klant klant) {
    this.klant = klant;
}

On pages I can access the sessionobject by using:#{sessionController.klantNaam}

Filburt
  • 17,626
  • 12
  • 64
  • 115
user2103237
  • 69
  • 1
  • 8
  • Mixing different types of annotations is not a good practice.. [look here](http://stackoverflow.com/questions/11986847/java-ee-6-javax-annotation-managedbean-vs-javax-inject-named-vs-javax-faces) – Omar Nov 16 '13 at 20:49

1 Answers1

0

The annotation ManagedProperty, as explained in the linked javadoc, should be used to inject a JSF bean annotated with ManagedBean.

Use Inject annotation for injecting a CDI bean.

perissf
  • 15,979
  • 14
  • 80
  • 117