java - JSF property transfer from backing bean A to backing bean B -


i'm getting deeper jsf 2.0 @ moment , lacking bit of understanding "transport" of managed bean properties 1 view other. searched bit haven't found example, if point me tutorial or explain things little bit i'd grateful.

so here scenario:

i'm developing small playground calendar application. first view select.xhtml contains calendar selector, user can pick specific date:

<html>   ...   <h:form>      <!-- calendar selector primefaces -->     <p:calendar value="#{calendarselect.date}" mode="inline" navigator="true" />      <p:commandbutton value="show entries date" action="day" />     ... 

my corresponding backing bean looks this:

@managedbean(name="calendarselect") @requestscoped public class calendarselectcomponent {    private date date = null;    ... // getters , setters 

now when submit form select.xhtml i'm forwarded day.xhtml

<html>   ...   <h:form>      current day ist:     <h:outputtext value="#{calendaredit.date}">       <f:convertdatetime pattern="dd.mm.yyyy" />     </h:outputtext> 

the backing bean looks this:

@managedbean(name="calendaredit") @viewscoped public class calendareditcomponent implements serializable {    private date date = null;   private calendarentrybean currententry = null;   private list<calendarentrybean> allentries = null;    .... 

i trying solve problem: how transfer date parameter selector editor?

i've tried number of options, 1 this:

<p:commandbutton value="show entries date" action="day" />   <f:setpropertyactionlistener target="#{calendaredit.date}" value="#{calendarselect.date}" /> </p:commandbutton> 

a debugger shows, indeed, date property of calendaredit populated value calendarselect, since day.xhtml new view, new calendareditcomponent backing bean being created , not 1 i've populated date selector in select view.

i've read 1 solution create sessionscoped backing bean retain it's values. not way think it's supposed work, because don't need information in session, want "travel" b. downside session based approach can use 1 selector , 1 editor per session - think isn't acceptible if think of multi window browsing , on.

i don't think i'm first 1 encountering such scenario , i'm sure jsf provides elegant solution haven't been able find solution.

so once again, if knows how approach - i'm listening! ;-)

the <f:setpropertyactionlistener> executed during invoke action phase of form submit. expects value still there @ point. since select bean request scoped, isn't there during form submit anymore. want instead pass request parameter inlined in output during render response. can <f:param>.

<p:commandbutton value="show entries date" action="day" />   <f:param name="date" value="#{calendarselect.dateasstring}" /> </p:commandbutton> 

it'll available request parameter (note understands strings, due nature of http). let jsf set request parameters managed properties, since edit bean view scoped, isn't possible @managedproperty. you've got gather externalcontext.

string dateasstring = externalcontext.getrequestparametermap().get("date"); 

true, that's clumsy. have used same bean , view , toggle visibility of select/edit forms rendered attribute. edit view after not directly openable/bookmarkable simple get, isn't it? ;)


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -