jsf - Can the Flash data be persisted after redirection? -


using jsf 2.1.29

in list.xhtml

<p:commandlink id="ownerviewlinkid" value="#{petowner.firstname} #{petowner.lastname} "  action="#{ownerandpetlistbean.viewpetownerfrmlist(petowner.id,petowner.userid,0)}"         onclick="pf('progrees_db').show()"         oncomplete="pf('progrees_db').hide()"         style="color:#0080ff;"> </p:commandlink> 

in listbean (viewscoped),

public void viewpetownerfrmlist(string owneridstr, string useridstr,             string petidstr) {     try {         facescontext.getcurrentinstance().getexternalcontext().getflash().put("ownerid",owneridstr);             facescontext.getcurrentinstance().getexternalcontext().getflash().put("userid",useridstr);             facescontext.getcurrentinstance().getexternalcontext().getflash().put("petid",petidstr);              facescontext.getcurrentinstance().getexternalcontext()                     .redirect("/ownerandpets/view");      } catch (exception e) {             log.warn("fl warning", e);     } } 

pretty-config.xml

  <url-mapping id="ownerandpetsview">        <pattern value="/ownerandpets/view" />                 <view-id value="/web-inf/views/ownerandpet/ownerandpetsview.xhtml" />       <action onpostback="false">#{ownerandpetviewbean.fillpage}</action>    </url-mapping> 

in viewbean (viewscoped),

string petidstr; string useridstr; string owneridstr; string firstname; //include getters , setters public void fillpage() {      petidstr = (string) facescontext.getcurrentinstance().getexternalcontext().getflash().get("petid");     useridstr = (string) facescontext.getcurrentinstance().getexternalcontext().getflash().get("userid");     owneridstr = (string) facescontext.getcurrentinstance().getexternalcontext().getflash().get("ownerid");      system.out.println(owneridstr+" "+useridstr+" "+petidstr);     firstname = getfromdbbyownerid(owneridstr);  } 

in view page,

<h:outputtext value="#{ownerandpetviewbean.firstname}"/> 

firstname displayed after redirect. on refreshing view page (by pressing f5), string firstname becomes null , id strings printed in viewbean's fillpage null. need on refresh, need refetch firstname ids must not null. had gone through link anyway persist flash data in request?

tried below not successful :

1.

facescontext.getcurrentinstance().getexternalcontext()                     .redirect("/ownerandpets/view?faces-redirect=true"); 

2.

facescontext.getcurrentinstance()     .getexternalcontext().getflash().keep("ownerid"); facescontext.getcurrentinstance()     .getexternalcontext().getflash().keep("userid"); facescontext.getcurrentinstance()     .getexternalcontext().getflash().keep("petid"); 

3.

facescontext.getcurrentinstance().getexternalcontext()     .getflash().setkeepmessages(true); facescontext.getcurrentinstance().getexternalcontext()     .getflash().setredirect(true); 

on refresh debugging, ids there in flash scope map on watching facescontext.getcurrentinstance().getexternalcontext().getflash() , same not displayed in watching facescontext.getcurrentinstance().getexternalcontext().getflash().get("petid"); (see fig 2).

values in flash map on refresh - fig 1 fig 2

update 1 (answer):

as suggested xtreme biker, added prerenderview view page.

<f:event type="prerenderview" listener="#{ownerandpetviewbean.fillpage}"/> .

from pretty-config.xml, remove or comment

<action onpostback="false">#{ownerandpetviewbean.fillpage}</action>

put not postback checking in fillpage method , added flash.keep in managed bean.

facescontext.getcurrentinstance().getexternalcontext().getflash().keep("ownerid"); 

the above method not work pretty-faces action tag (if used instead of prerenderview) , page no values.

the prettyfaces action out of scope of current flash state. don't know how pretty action works, need set flash.keep in same request cycle redirection performed (if using pretty, that's done post-redirect-get pattern).

anyway, the docs example pretty action shows @requestscoped bean, don't know compatibility view scope , flash state, consequently. prefer use f:event='prerenderview' checking postbacks if still in jsf 2.1. if jsf 2.2, use f:viewaction, without having check postbacks.

see also:


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -