i have 2 pages(let's page1 , page2), , 1 magaedbean each page (mb1 , mb2). in mb1, have instance of mb2, attributes setted method in mb1. this:
public mb1(){}//default constructor private mb2 mb2;//instance of mb2 inside mb1
what want is, method in mb1, open view page2 in way controller of page2(mb2) instance stored in mb1.
both managedbeans must viewscoped, know can use session scoped not need. tere way this?
why managed bean responsible of initializing one? i'd rather provide necessary information mb2
can initialize himself.
if you're set on passing object , avoiding mb2
's self initialization (and assuming you're using jsf 2), suggest take @ jsf's flash scope.
tough flash not scope per se, it's feature based (afaik) on ruby's implementation of post - redirect - pattern. instead of having bean parameter, can create own object stores data , have mb2
operate on it.
when need navigate page2
, store item in flash , retrieve later, when mb2 created.
to store need flash
, can obtained in multiple ways:
facescontext.getcurrentinstance().getexternalcontext().getflash();
or
@managedproperty("#{flash}") private flash flash; public void setflash(flash jsfflash) { flash = jsfflash; }
flash map (just ones request , session), can put object there:
managingobject o = new managingobject(); //initialize object , set desired properties. flash.put("managingobject", mo);
you can, then, object in mb2
obtaining flash
, taking object it, example, in prerenderview
defined event.
Comments
Post a Comment