jsf 2 - @ManagedProperty annotated type returns null -


i have service bean:

@stateless public class bookservice {     @persistencecontext(unitname="persistentunit")     protected entitymanager entitymanager;      public bookmodel find(long id) {        return entitymanager.find(bookmodel.class, id);     } } 

and backing bean facelet page is:

@managedbean(name = "bookbean") @requestscoped public class bookbean implements serializable {     @ejb     private bookservice bookservice;      @managedproperty(value="#{param.id}")     private long id;      private datamodel<bookmodel> books;     private bookmodel currentbook;      @postconstruct     public void init() {         if (id == null) {            // update: retrieve list of books.         } else {             // update: id shouldn't null here.            // detail info book using id            currentbook = bookservice.find(id);         }     }      public long getid() {        return id;     }       public void setid(long id) {        this.id = id;     }       public bookmodel getcurrentbook() {        return currentbook;     }      public void setcurrentbook(bookmodel currentbook) {        this.currentbook = currentbook;     }  } 

why value of id returns null though url returned bookedit.jsf?id=5418 don't understand this.

also, find entitymanager#find method quite restrictive in accept primary key value second parameter. if want pass [hashed] value instead of primary key. how can entitymanager#find method?

p.s. notice entitymanager#find requirement same both openjpa , eclipselink implementations. hmm...

i tried in 1 of managed beans, , working. here's relevant code, it's same yours:

@managedbean @requestscoped public class testbean {     @managedproperty(value = "#{param.id}")     private long prop;      @postconstruct     public void init() {         system.out.println(prop);         // prints 1234 if go url http://localhost/page.jsf?1234     }      public long getprop() {         return prop;     }      public void setprop(long prop) {         this.prop = prop;     } } 

i'm running on glassfish 3.1.1. thought had maybe injected ejb somehow messing request scope in managedbean?


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -