2

In a @RequestScoped bean, I need another bean that is @ViewScoped.

So I tried:

@ManagedBean
@RequestScoped
public class RequestBean
{
  @ManagedProperty( value = "#{viewBean}" )
  private ViewBean viewBean;

  public void setViewBean(...){...}

  public void doSomething(){
     // ...
  }
}

The method doSomething() is called by a buttonClick and performs some ImageStreaming (which is the reason for my Bean to be RequestScoped). The injection itself works fine in the first place, but as soon as doSomething() is being called, I get this exception:

com.sun.faces.mgbean.ManagedBeanCreationException: Could not determine property viewBean for managed bean requestBean

(Translated message, could be slightly different)

   at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:615)
   ...
Caused by: java.lang.NullPointerException
   at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.getFromScope(BeanManager.java:563)
   ...

...which is pretty much the same when you forget to implement the setter method. What is wrong here?

jp-jee
  • 1,502
  • 3
  • 16
  • 21
  • Try putting a getter method. – Adrian Mitev Dec 15 '13 at 18:28
  • getter already exists. – jp-jee Dec 15 '13 at 18:33
  • Is the name of your ViewBean named "viewBean" ? Per default it should be.. but try @ManagedBean(name = "viewBean") – Matthias H Dec 16 '13 at 06:36
  • Do you also provide setter MEthod for your ViewBean ? Thats Mandatory – Matthias H Dec 16 '13 at 06:39
  • I just tried explicitly declaring the name of the bean. Setter exists for sure, see code above. No luck. Again: The injection works one time - there must be a relation to the Streaming (see [here](http://stackoverflow.com/questions/13651248/managedbean-return-null-to-graphicimage-in-primefaces?rq=1)), since only the injection during the mentioned second request fails for some reason. – jp-jee Dec 16 '13 at 09:32

1 Answers1

1

I suggest you to try to use CDI you have a ConversationalScope that allows you to have a similar View Scoped and you can inject the bean with the simple @Inject annotation

Cesar Loachamin
  • 2,740
  • 4
  • 25
  • 33
  • I edit my answer, Sorry but the confusion but you can inject a ViewScoped bean in a RequestScoped the opposite is wrong, sorry my mistake. – Cesar Loachamin Dec 15 '13 at 19:06