0

I am a beginner in JSF and thank you for helping me. I have 2 Managed Beans A and B. I would simply like to recover 2 variables from the A bean to the B bean. Is there a solution? I try for hours things found on the internet but nothing works! PLEASE could you give me a start of solution?

I tried (but causes a null pointer):

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@SessionScoped
@Named
public class AccueilManagerBean implements Serializable {
...
...



import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@SessionScoped
@Named
public class NoteManagerBean implements Serializable {

    @ManagedProperty(value = "#{accueilManagerBean}")
    private AccueilManagerBean acm;

public NoteManagerBean() {
}

@PostConstruct
public void init() { System.out.println(acm.getPageHauteur());
}
  • I need to find a duplicate but in this case, since you seem to want to access a full bean, just replace `@ManagedProperty(value = "#{accueilManagerBean}")` with `@Named("accueilManagerBean")` See https://stackoverflow.com/questions/9921324/managedproperty-in-cdi-named-bean-returns-null (not the right duplicate in my opinion, I might rewrite that a little, but all the info is in there) – Kukeltje Jun 30 '18 at 15:44
  • You bean is a CDI managed bean, not a JSF managed one. This is a better one: https://stackoverflow.com/questions/17390792/managedproperty-does-not-work-in-a-cdi-managed-bean – Kukeltje Jun 30 '18 at 16:08
  • 1
    Possible duplicate of [@ManagedProperty does not work in a CDI managed bean](https://stackoverflow.com/questions/17390792/managedproperty-does-not-work-in-a-cdi-managed-bean) – Kukeltje Jun 30 '18 at 16:08
  • Replace @ManagedProperty(value = "#{accueilManagerBean}") with @Named("accueilManagerBean") : Error --> java.lang.NullPointerException – Denis Duval Jul 02 '18 at 03:21
  • Oh sorry typo... read the duplicate... `@Named` should be `@Inject` as a replacement – Kukeltje Jul 02 '18 at 04:25
  • I'm lost. Please can you give me a complete example? Thank you – Denis Duval Jul 05 '18 at 02:21
  • Replace `@ManagedProperty(value = "#{accueilManagerBean}")` with `@Inject("accueilManagerBean")` – Kukeltje Jul 05 '18 at 05:12

0 Answers0