Brief Summary (for those that care):
1. Define the managed bean in faces config.
2. Define the t:saveState tag in your JSP
3. Command button called that executes the code in the action class
below.
Then redirects to the page with the saveState tag.
JSP...
<t:saveState id="saveStateBean02" value="#{nonConformingMaterial}"/>
Action Class...
ValueBinding binding =
FacesContext.getCurrentInstance().getApplication().createValueBinding("#
{nonConformingMaterial}");
NCM ncmObject =
(NCM)binding.getValue(FacesContext.getCurrentInstance());
// the current page values - ncmObject - not used here
// Send the new values to be displayed on the page.
binding.setValue(FacesContext.getCurrentInstance(), newNCMObject);
Faces Config
<managed-bean>
<managed-bean-name>nonConformingMaterial</managed-bean-name>
<managed-bean-class>org.me.NCM</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Jeff.
-----Original Message-----
From: Jeffrey Porter [mailto:[EMAIL PROTECTED]
Sent: 18 October 2005 09:00
To: MyFaces Discussion
Subject: RE: FacesContext/VariableResolver to get bean - how to set a
bean?
Thanks Mike.
I'll follow your example for the moment.
It doesn't seem the most logical way to do it. I'm surprised that
MyFaces doesn't have a more structured way to do this.
Anyone else have a view on this?
Jeff.
-----Original Message-----
From: Mike Kienenberger [mailto:[EMAIL PROTECTED]
Sent: 17 October 2005 18:06
To: MyFaces Discussion
Subject: Re: FacesContext/VariableResolver to get bean - how to set a
bean?
Yeah, it's a bit of a changeover.
Let me give you one example of how I'm doing this. This is not the
only way to solve the problem, but how I'm doing it.
I have a commandLink inside a t:dataList (very similar to a dataTable)
that populates a request-scoped bean and redirects to a new page.
<h:commandLink action="#{editAnnouncementsPage.showContentData}" />
I have a request-scoped backing bean that supplies values to display
on this new page.
<managed-bean>
<managed-bean-name>showContentDataPage</managed-bean-name>
<managed-bean-class>myPackage.jsf.page.ShowContentData</managed-bean-cla
ss>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
In my showContentData page, I programmically grab a reference to my
backing bean, and populate it with the contents of the current row
variable.
public String showContentData()
{
Content selectedContent =
(Content)this.announcementContentDataList.getRowData();
ValueBinding binding =
FacesContext.getCurrentInstance().getApplication().createValueBinding("#
{showContentDataPage}");
ShowContentData showContentDataPage =
(ShowContentData)binding.getValue(FacesContext.getCurrentInstance());
showContentDataPage.setContent(selectedContent);
return "showSelectedContentData";
}
To preserve the data, I use t:saveState to preserve the content value
of the backing bean, on both the original page, and the new page:
<t:saveState id="savedSelectedAnnouncementContent"
value="#{showContentDataPage.content}"/>
So the order of events is this:
1) user selects command-link, submitting form
2) command-link action retrieves (creating if necessary) the
showContentDataPage backing bean in invokeApplication phase.
3) command-link action populates request-scoped backing bean with new
"content" value.
4) t:saveState component stores "content" value into component tree
during RenderResponse phase.
5) ?
6) Your components can now access this bean to provide values on the
new page in the RenderREsponse phase.
I'm not entirely certain what's going on at step 5. I thought I
understood why I needed to use saveState but I can't figure out why
now. I do know that if I remove the t:saveState attributes, things
no longer work, so there is a reason.
Maybe someone else can jump in.
Or you can just use it, and figure out why it works later, like I'm
now doing. :)
On 10/17/05, Jeffrey Porter <[EMAIL PROTECTED]> wrote:
>
> So if I have JSP-A with a button on, this links to an action.
> The action loads some data into BeanA, then redirects to a new page
> (JSP-B).
> What do I have to do in the action class to get BeanA displayed on
> JSP-B?
>
> I've put in "value="#{myManagedBean.workNumber}"/>" but I'm at a loss
of
> what the action class must do with the bean.
>
> Thanks
>
> p.s> I may be approaching this problem in the wrong way. I'm a ex
> Strut's Guy.
> :-)
>
>
> -----Original Message-----
> From: Mike Kienenberger [mailto:[EMAIL PROTECTED]
> Sent: 17 October 2005 17:29
> To: MyFaces Discussion
> Subject: Re: FacesContext/VariableResolver to get bean - how to set a
> bean?
>
> You'd just set the value attribute of the component to point to your
> managed bean.
>
> <h:outputText id="workNumberInput"
value="#{myManagedBean.workNumber}"/>
>
> If "myManagedBean" has request scope, you'll need to preserve it using
> t:saveState so it's still available on the next page. I'm not
> certain that you can do this if you use a <redirect /> tag in your
> navigation rules, so you'd have to use some other method to preserve
> them (session-scoped bean, maybe, or change to server-side state
> management.)
>
> On 10/17/05, Jeffrey Porter <[EMAIL PROTECTED]>
wrote:
> >
> >
> >
> >
> >
> > I understand how to get a bean from a jsp using FacesContext &
> > VariableResolver.
> >
> >
> >
> > Yet when I redirect to a new page I want it to display a form
> containing
> > data from a bean I've already populated.
> >
> >
> >
> > I can do this with tables since I've created a managed-bean that is
> used in
> > a h:dataTable tag.
> >
> >
> >
> > But with a page that has textfields/radio buttons etc. How do I
> populate
> > them?
> >
> >
> >
> > Hope my question makes sense.
> >
> >
> >
> > If anyone can point me in the direction of some info, it would be
> great.
> >
> >
> >
> > Thank
> >
> > Jeff
> >
> >
>