David
David

Reputation: 180

Trouble using ManagedProperty

I'm trying to share an object between several SessionScoped beans. I get errors though and I really don't know why.

@ManagedProperty(value="#{tb}")
private testBean tb;

I believe that this is the right syntax, but any call like tb.getName results in an exception.

@ManagedBean(name = "tb")
public class testBean 
{
    private String name = "sumthing";

    public void setName(String name)
    {
        this.name = name;
    }

    public String getName()
    {
        return this.name;
    }
}

Have I completely misunderstod how ManagedProperty works?

Upvotes: 1

Views: 728

Answers (3)

eugenevd
eugenevd

Reputation: 840

You can also take a look at the Flash scope, the idea is to use this if you just want to pass values/objects from one view to another, and you don't want to burden the server with a session state.

For an example see: http://jugojava.blogspot.com/2011/06/jsf2-flash-scope-example.html

Upvotes: 0

Buhake Sindi
Buhake Sindi

Reputation: 89189

Why not add @SessionScoped to your JavaBean? See my explanation to this SO Question. Secondly, you don't do #{tb.getName}, rather use EL Expression #{tb.name} instead.

Upvotes: 0

Jigar Joshi
Jigar Joshi

Reputation: 240956

Probably your consumer class doesn't have setters/getters for tb

Upvotes: 2

Related Questions