You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kevin Galligan <ma...@kgalligan.com> on 2006/05/10 18:45:00 UTC

populating request scope managed bean

I'm have a really hard time doing something that, in my mind, should be very
simple.  Populating a managed bean with scope 'request'.  Essentially, I
have a dataTable, which is bound to a UIData variable in the backing bean,
and a commandLink which pulls the selected object and pushes it into the
request collection with...

FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(key,
value);

Then we go to the detail page.  By the time we get there, no object.  It is
not redirecting, so this *should* work, I think.

I changed it to use session instead of request, and set the object with...

FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,
value);

This works.  Any ideas?  I assume that I'm initalizing the request bean
incorrectly, but I don't know how.  I'm probably going back to the session
method so I can move on for now, but any help would be greatly appreciated.
I want to use 'saveState' to handle 'request-session' or 'request-thread'
scope state, as if this works, it looks to be just the thing I've been
missing with struts and jsf.  However, the "simple" part I can't get past.

Thanks in advance,
-Kevin

Question for tiles.xml connection refused IO error

Posted by ya...@cabm.rutgers.edu.
Hi, experts

I am using myfaces(v1.1.1)+tiles, but just started seeing the error
reading tiles.xml as follows.  I was using defualt DTD setting in my
tiles.xml to access an exteranl link located in jakarta, but it seems that
it is not working. So, could someone advise me how to use system dtd ?

I tried several versions, but it does not work. I got a dtd from :
struts-1.2.8/lib/tiles-config_1_1.dtd
Is this the right one ?

I have moved tiles-config_1_1.dtd to under /WEB-INF.

Thanks,
yasushi

=== error  ==
org.apache.struts.tiles.DefinitionsFactoryException: IO Error while
parsing file '/WEB-INF/tiles.xml'. Connection refused

=== initial tiles.xml and got the above error ==
<!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration//EN"
   "http://jakarta.apache.org/struts/dtds/tiles-config.dtd">

== I changed the above tryhing to use system dtd, but did not work ==
<!DOCTYPE tiles-definitions SYSTEM
"http://127.0.0.1:9090/PLIMS/WEB-INF/tiles-config_1_1.dtd">

Re: populating request scope managed bean

Posted by Kevin Galligan <ma...@kgalligan.com>.
I still can't get the request scope top level beans to populate.  I can get
a reference to a request scope bean and set an object value on it.  Strange.

However, regardless, after trying out 't:updateActionListener' I see why its
cool.  I have to rearchitect my app a bit, but it does make life quite a bit
easier.

Thanks.

On 5/10/06, Mike Kienenberger <mk...@gmail.com> wrote:
>
> On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
> > I'm frustrated because I'm not doing a redirect, but it still just won't
> > work.  So, how would I set a top level managed bean with a value at the
> > request scope without putting it into the session?
>
> It is possible to do this programmically (I used to do it this way),
> but it's far easier to use t:updateActionListener.
>
> If you want to keep fighting it, you can take a look at
>
> http://wiki.apache.org/myfaces/AccessingOneManagedBeanFromAnother
>
> Option 1) context.getExternalContext().getRequestMap().put("testObject",
> testObject) looks like the right track to me, so that'd probably the
> path to pursue (Search MyFaces user list archives for postings on
> managed beans and maps, probably written by Craig McClanahan.)
>
> However,  doing it like this is far easier:
>
> <h:commandLink
>     value="Select Detail"
>    action="optionally do something">
>
>    <t:updateActionListener
>         property="#{testObject}"
>         value="#{currentRowObject}" />
>
> </h:commandLink>
>
> One thing that might be required is to add a layer of indirection:
>
>    <t:updateActionListener
>         property="#{someBean.testObject}"
>         value="#{currentRowObject}" />
>

Re: populating request scope managed bean

Posted by Mike Kienenberger <mk...@gmail.com>.
On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
> I'm frustrated because I'm not doing a redirect, but it still just won't
> work.  So, how would I set a top level managed bean with a value at the
> request scope without putting it into the session?

It is possible to do this programmically (I used to do it this way),
but it's far easier to use t:updateActionListener.

If you want to keep fighting it, you can take a look at

http://wiki.apache.org/myfaces/AccessingOneManagedBeanFromAnother

Option 1) context.getExternalContext().getRequestMap().put("testObject",
testObject) looks like the right track to me, so that'd probably the
path to pursue (Search MyFaces user list archives for postings on
managed beans and maps, probably written by Craig McClanahan.)

However,  doing it like this is far easier:

<h:commandLink
    value="Select Detail"
   action="optionally do something">

   <t:updateActionListener
        property="#{testObject}"
	value="#{currentRowObject}" />

</h:commandLink>

One thing that might be required is to add a layer of indirection:

   <t:updateActionListener
        property="#{someBean.testObject}"
	value="#{currentRowObject}" />

Re: populating request scope managed bean

Posted by Kevin Galligan <ma...@kgalligan.com>.
Basically I can't get the following to work...

faces-config snippet...

<managed-bean>
        <managed-bean-name>testObject</managed-bean-name>
        <managed-bean-class>kg.web.jsf.test.TestObject</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

I have a datatTable with a list of these as simple pojo's.  When clicking on
one, a command link calls a function on the page's backing bean...

public String editTestObject()
    {
        FacesContext context = FacesContext.getCurrentInstance();

        TestObject testObject = (TestObject)testTable.getRowData();

        //This is where the setting code would go...

        return "editTestObject";
    }

'testTable' is a UIData object.  I've run the debugger, and the 'getRowData'
returns the correct value.  However, no matter what I do, I can't get the
managed bean set with that value.  I've tried...

1) context.getExternalContext().getRequestMap().put("testObject",
testObject);

2) ValueBinding binding = context.getApplication
().createValueBinding("#{testObject}");

        binding.setValue(context,testObject);

3) ValueBinding binding = context.getApplication
().createValueBinding("#{testObject}");

        TestObject fromConfig = (TestObject)binding.getValue(context);
        binding.setValue(context,testObject);

The third one I tried just to see if getting the value first would cause it
to be created to avoid the re-create later.  Anyway, if stuff the object
into the sessionMap instead of these options, it works.

I'm frustrated because I'm not doing a redirect, but it still just won't
work.  So, how would I set a top level managed bean with a value at the
request scope without putting it into the session?

On 5/10/06, Mike Kienenberger <mk...@gmail.com> wrote:
>
> On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
> > I see how those work, but none of them is really doing what I want to
> do.
> > You know?  Is it not possible to manually populate a request scope bean?
>
> Guess I'm not following what you're asking.
>
> For what it's worth, I manually populate request-scoped beans with
> t:saveState when I want the value to persist to the next request (ie,
> make the request-scoped bean act like a page-scoped bean), and I use
> t:updateActionListener when I want to populate a request-scoped bean
> with a specific value (like the detail record selected) in the next
> request.
>

Re: populating request scope managed bean

Posted by Mike Kienenberger <mk...@gmail.com>.
On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
> I see how those work, but none of them is really doing what I want to do.
> You know?  Is it not possible to manually populate a request scope bean?

Guess I'm not following what you're asking.

For what it's worth, I manually populate request-scoped beans with
t:saveState when I want the value to persist to the next request (ie,
make the request-scoped bean act like a page-scoped bean), and I use
t:updateActionListener when I want to populate a request-scoped bean
with a specific value (like the detail record selected) in the next
request.

Re: populating request scope managed bean

Posted by Kevin Galligan <ma...@kgalligan.com>.
I see how those work, but none of them is really doing what I want to do.
You know?  Is it not possible to manually populate a request scope bean?

On 5/10/06, Mike Kienenberger <mk...@gmail.com> wrote:
>
> See
>
> http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters
>
> Under
>
> Working with tables
>
> in the wiki
>
>
> On 5/10/06, Kevin Galligan <kg...@gmail.com> wrote:
> > Sorry for the self-followup.  I'm pulling my hair out.
> >
> > Basically, I've modified my code to following this...
> >
> >
> http://www.groundside.com/blog/content/DuncanMills/J2EE+Development/2005/04/06/Drilldown_Edit_with_JSF.html?page=comments
> >
> > Still doesn't work.  Then I created a set of test objects and screens
> that
> > went down to the absolute basics.  Didn't work.  I then changed my value
> > object to be session scope instead of request, but still set it with ...
> >
> > ValueBinding binding =
> > context.getApplication().createValueBinding("#{testObject}");
> >  binding.setValue(context,testObject);
> >
> > Even set as session, this didn't work.  I know that if I just put it in
> the
> > session map, that will work, but there must be a way to set a managed
> bean
> > in request scope from code.  However, I cannot get it to work.  Please,
> > please help.  At least tell me you do something like this, and generally
> how
> > you accomplish it.  Losing my mind.
> >
> >
> > On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
> > >
> > > I'm have a really hard time doing something that, in my mind, should
> be
> > very simple.  Populating a managed bean with scope
> 'request'.  Essentially,
> > I have a dataTable, which is bound to a UIData variable in the backing
> bean,
> > and a commandLink which pulls the selected object and pushes it into the
> > request collection with...
> > >
> > >
> > FacesContext.getCurrentInstance
> ().getExternalContext().getRequestMap().put(key,
> > value);
> > >
> > > Then we go to the detail page.  By the time we get there, no
> object.  It
> > is not redirecting, so this *should* work, I think.
> > >
> > > I changed it to use session instead of request, and set the object
> with...
> > >
> > >
> > FacesContext.getCurrentInstance
> ().getExternalContext().getSessionMap().put(key,
> > value);
> > >
> > > This works.  Any ideas?  I assume that I'm initalizing the request
> bean
> > incorrectly, but I don't know how.  I'm probably going back to the
> session
> > method so I can move on for now, but any help would be greatly
> appreciated.
> > I want to use 'saveState' to handle 'request-session' or
> 'request-thread'
> > scope state, as if this works, it looks to be just the thing I've been
> > missing with struts and jsf.  However, the "simple" part I can't get
> past.
> > >
> > > Thanks in advance,
> > >
> > > -Kevin
> > >
> >
> >
>

Re: populating request scope managed bean

Posted by Mike Kienenberger <mk...@gmail.com>.
See

http://wiki.apache.org/myfaces/ExecutingMethodsFromLinkButtonParameters

Under

Working with tables

in the wiki


On 5/10/06, Kevin Galligan <kg...@gmail.com> wrote:
> Sorry for the self-followup.  I'm pulling my hair out.
>
> Basically, I've modified my code to following this...
>
> http://www.groundside.com/blog/content/DuncanMills/J2EE+Development/2005/04/06/Drilldown_Edit_with_JSF.html?page=comments
>
> Still doesn't work.  Then I created a set of test objects and screens that
> went down to the absolute basics.  Didn't work.  I then changed my value
> object to be session scope instead of request, but still set it with ...
>
> ValueBinding binding =
> context.getApplication().createValueBinding("#{testObject}");
>  binding.setValue(context,testObject);
>
> Even set as session, this didn't work.  I know that if I just put it in the
> session map, that will work, but there must be a way to set a managed bean
> in request scope from code.  However, I cannot get it to work.  Please,
> please help.  At least tell me you do something like this, and generally how
> you accomplish it.  Losing my mind.
>
>
> On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
> >
> > I'm have a really hard time doing something that, in my mind, should be
> very simple.  Populating a managed bean with scope 'request'.  Essentially,
> I have a dataTable, which is bound to a UIData variable in the backing bean,
> and a commandLink which pulls the selected object and pushes it into the
> request collection with...
> >
> >
> FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(key,
> value);
> >
> > Then we go to the detail page.  By the time we get there, no object.  It
> is not redirecting, so this *should* work, I think.
> >
> > I changed it to use session instead of request, and set the object with...
> >
> >
> FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,
> value);
> >
> > This works.  Any ideas?  I assume that I'm initalizing the request bean
> incorrectly, but I don't know how.  I'm probably going back to the session
> method so I can move on for now, but any help would be greatly appreciated.
> I want to use 'saveState' to handle 'request-session' or 'request-thread'
> scope state, as if this works, it looks to be just the thing I've been
> missing with struts and jsf.  However, the "simple" part I can't get past.
> >
> > Thanks in advance,
> >
> > -Kevin
> >
>
>

Re: populating request scope managed bean

Posted by Kevin Galligan <kg...@gmail.com>.
Sorry for the self-followup.  I'm pulling my hair out.

Basically, I've modified my code to following this...

http://www.groundside.com/blog/content/DuncanMills/J2EE+Development/2005/04/06/Drilldown_Edit_with_JSF.html?page=comments

Still doesn't work.  Then I created a set of test objects and screens that
went down to the absolute basics.  Didn't work.  I then changed my value
object to be session scope instead of request, but still set it with ...

ValueBinding binding = context.getApplication
().createValueBinding("#{testObject}");
binding.setValue(context,testObject);

Even set as session, this didn't work.  I know that if I just put it in the
session map, that will work, but there must be a way to set a managed bean
in request scope from code.  However, I cannot get it to work.  Please,
please help.  At least tell me you do something like this, and generally how
you accomplish it.  Losing my mind.

On 5/10/06, Kevin Galligan <ma...@kgalligan.com> wrote:
>
> I'm have a really hard time doing something that, in my mind, should be
> very simple.  Populating a managed bean with scope 'request'.  Essentially,
> I have a dataTable, which is bound to a UIData variable in the backing bean,
> and a commandLink which pulls the selected object and pushes it into the
> request collection with...
>
> FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put(key,
> value);
>
> Then we go to the detail page.  By the time we get there, no object.  It
> is not redirecting, so this *should* work, I think.
>
> I changed it to use session instead of request, and set the object with...
>
> FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key,
> value);
>
> This works.  Any ideas?  I assume that I'm initalizing the request bean
> incorrectly, but I don't know how.  I'm probably going back to the session
> method so I can move on for now, but any help would be greatly appreciated.
> I want to use 'saveState' to handle 'request-session' or 'request-thread'
> scope state, as if this works, it looks to be just the thing I've been
> missing with struts and jsf.  However, the "simple" part I can't get past.
>
> Thanks in advance,
> -Kevin
>