jsf - How to pass bean property from one view to another view -


i'm using jsf 2.1 , primefaces:

i have view scoped managed bean managed property , method set on other view scoped managed bean , forward other page referencing managed bean:

@managedbean @viewscoped public class hellomb {     @managedproperty("othermb")    private othermb other;     public string changeothermb() {       othermb.setanyobject(new object());       return "otherpage.xhtml";    }  }  @managedbean @viewscoped public class othermb {     private object o;         public void setanyobject(object o) {       this.o = o;    }  } 

so, when otherpage rendered o null.

you have idea how solve this? how can retain object in @viewscoped managed bean , keep live on other page without using @sessionscoped?

the view scope destroyed , recreated once navigate different jsf view. know, view scope lives long you're interacting same jsf view. in particular case end 2 instances of #{othermb} managed bean during 1 request. 1 instance used source view , instance used destination view.

as second view created within same request, pass request attribute.

@managedbean @viewscoped public class hellomb implements serializable {      public string changeothermb() {         externalcontext ec = facescontext.getcurrentinstance().getexternalcontext();         ec.getrequestmap().put("anyobject", anyobject);         return "otherpage.xhtml";     }  } 
@managedbean @viewscoped public class othermb {      private object anyobject;          @postconstruct     public void init() {         externalcontext ec = facescontext.getcurrentinstance().getexternalcontext();         this.anyobject = ec.getrequestmap().get("anyobject");     }  } 

i wonder if you're aware importance of idempotent vs non-idempotent requests. perhaps actually need "plain vanilla" link without need invoke view scoped bean action method. see last "see also" link below extensive example on that.

see also:


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -