0

Imagine I have a bean which is SessionScoped. ( Call it: Bean A )

When I request a page that accesses this bean, this bean is initialized and some of its properties are set accordingly.

Then I access some other page which has nothing to do with this bean. ( Bean A ) However, I still want to see this beans state in my debugger. How can I do this?

If my question is not clear I will try to rephrase it:

@SessionScoped
@Named
public class User{
    private String name;
    //getters,setters
}

Now imagine a user.xhtml, which sets a name to user.name..

Now imagine I am on page someotherpage.xhtml and I am debugging my application.

Since this bean is sessionscoped, meaning still in scope, it must be reachable somehow by the debugger. But how?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • Which application server are you using? – dratewka Jun 08 '13 at 09:27
  • There's no much sense in what you're trying to accomplish (at least I can't find a real world use case to handle this scenario). Still, the best idea would be retrieving the session scoped bean somewhere in your code following one of the many ways explained by BalusC in the link posted at bottom of XtremeBiker's answer. – Luiggi Mendoza Jun 08 '13 at 14:52

2 Answers2

1

I'm not familiar with IntelliJ, however, I saw there's a console debug tool, where you can access variable values while executing. Just stop the execution where you want and use it to access the faces context and get the managed bean using its name:

  FacesContext context = FacesContext.getCurrentInstance();
  context.getApplication().evaluateExpressionGet(context, "#{" + beanName + "}", Object.class);

When using CDI, you can do it like below:

@Inject
private Bean bean;

Got from this SO answer.

Regards.

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • I guess you could adapt the CDI answer provided by BalusC since that's what OP's using (note the `@Named` annotation in his code). – Luiggi Mendoza Jun 08 '13 at 14:53
0

Session scoped objects will have a reference in the HTTP session. As long as you do something with the HTTP request, you should be able to get to the session then the session scoped bean.

John Ament
  • 11,595
  • 1
  • 36
  • 45