jsf - Scopes and @PostConstruct -


i'm using jsf 2, primefacces 3.4 , cdi. i've 2 pages: page1.xhtml , page2.xhtml. each page has own managed bean: page1bean , page2bean.

page1.xhtml has <p:remotecommand> actionlistener displays page2.xhtml.

page2.xhtml contains 3 components under <ui:include> , 1 submit button. each of 3 components bound different managed beans component1bean, component2bean , component3bean. submit button shows page1.xhtml.

those 3 componentxbeans have @postconstruct method initialization code. tried following scoped on beans:

  • @sessionscoped: works fine single submit operation. when repeat it, beans not reinitialized @postconstruct because session scoped.
  • @viewscoped: @postconstruct gets called multiple times.
  • @conversationscoped: same behavior @viewscoped.

why @postconstruct called multiple times in view , conversation scope? how can let them called once per submit operation?

running initialization code under 'prerender' every time, not correct. since initialization wipe out data want.

separate prerender initialization. can either hook them separately, or have flag call initialize() once.

avoid session-scoped beans if possible; session-scoping mark of badly-designed web applications , (in it's simplest forms) bad way implement inter-page flow. pass url or post parameters between web pages implement flow.

if necessary, inter-page parameters can unique handles objects stored in httpsession. don't dump stuff session without either being genuinely global application (such "loggedinuser") or referenced uniquely-allocated handle.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -