jsf 2 - Initialize Managed Bean from view -


i having difficult time dealing scope should use on application.

i using primefaces using initial view layout. outside of layout have dialogs used many different managed beans.

within layout have header, footer navgiation on left , current view in center. view looks follows:

<h:body id=body">    <p:layoutunit id=head" position="top">          <ui:insert name="header">    </p:layoutunit>    <p:layoutunit id=head" position="bottom">          <ui:insert name="footer">    </p:layoutunit>    <p:layoutunit id=head" position="left">          <ui:insert name="menu">    </p:layoutunit>    <p:layoutunit id=head" position="right">          <ui:insert name="main">    </p:layoutunit>     <p:dialog widgetvar="addaddressdialog" header="add new address">        <h:form id="insertaddress">             <h:inputtext id="insert_address" label="address" />        </h:form>    </p:dialog>     <p:dialog widgetvar="updateaddressdialog" header="add new address">        <h:form id="updateaddress">             <h:inputtext id="update_address" value=#{addressbean.selectedaddress.address" />        </h:form>    </p:dialog> 

the issue having when application first loads addressbean's @postconstruct getting called because view being loaded. in @postconstruct initialize list of addresses associated specific id called contactid. @ point though contactid has not been instantiated. happens once user interacts "main" view.

my scope addressbean @viewscope works find first time contactid set. after continues retain information populated if contactid changes because @postconstruct never called again , view never seems go out of scope.

i have tried @requestscope , works well. run problem when displaying addresses in datatable inside "main" view. have button @ bottom of datatable called insertaddressdialog.show(). opens first time , can insert data 1. view datatable never shows new record have inserted because guess view has been lost @ point. , 2. button on datable no longer alive or active, dialog wont open after first time user inserts record.

this seems should easy thing application has many nested views causing problem. insight on how handle help.

this doesn't sound primefaces issue.

the viewscoped bean remain in scope long not navigate away page (view) associated. requestscoped bean re-instantiate every time interact it. if you're trying store variables requestscoped bean on 1 interaction, update database variables on second interaction, second interaction re-instantiate bean , you're variables gone (okay, variables still there - values disappear).

do have compelling reason using @postconstruct initialize addresses? sounds have main page users start interact program, main page user enters (or program otherwise retrieves) user's contactid. contactid variable used populate data table showing addresses associated user's contactid. sounds error in bean logic.

you need contactid first, use fill data table. don't know how program/user interacts bean provide contactid. if contactid input user, don't initialize address list in @postconstruct because initialized before contactid entered. if program obtaining contactid automatically from, say, variable of type user (which knows because user signed in , program created/retrieved user's contactid database), should able include code in @postconstruct - before data table initialized.

or, instead of using @postconstruct, include method call in web page @ point before page (view) references variables. can put method call right on page:

#{mybean.mymethod} other code here...

the bean should called , constructed before method call, , user's contactid should available bean's data manipulation. (i'm making assumption on last point since can't see bean logic.)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -