This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes Bean request Scope won't Call method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Bean request Scope won Watch "Bean request Scope won New topic
Author

Bean request Scope won't Call method

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

I am not sure why I am running into this problem. I have a bean that is in request scope. There are components on the page whose rendered attribute is used. Components that aren't rendered on the initial page display work fine and the commandButton's actionListener methods are called just fine. However, commandButton methods that are rendered on a change to their rendered attributes boolean values aren't being called. If I change the scope to session, it works fine. Putting the page in the session requires too much cleanup when I change page states/modes so I would rather have it in the request scope. Below is some code. I hope someone can see my hopefully stupid mistake(s).





Looking at the code the problem is mainly with the <h:commandButton actionListener="#{categoryAdmin.update}" value="Update" rendered="#{cat.editable}" /> component. When this is rendered after clicking the Edit button, and then I click the Update button, the update() method is never called. NEVER. However, placing the bean in session scope, and it works as expected. Any help is greatly appreciated.


GenRocket - Experts at Building Test Data
Rick Beaver
Ranch Hand

Joined: Dec 14, 2004
Posts: 464
I have encountered a similar issue. I don't know why it fixed it, it logically shouldnt matter but just as a starting point can you try having your update method return a String - return anything, it doesn't need to relate to a faces-config.xml entry.

I know it doesnt make sense, it didnt to me either, but give it a whirl.


ph34r my 133t j4v4 h4><0r1ng sk177z
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Yeah, that doesn't work. I am still stumped by this. The way it is acting is if a component is not rendered the first time the page is requested then it doesn't bind the actionListener method to the component. So when the page is rendered again with the component showing, the method is never called.

That just doesn't make sense to me.
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Is your binding in the constructor - or called from there? I had a similar problem, solved it by putting it into a setId method and did a save state which called it every trip back to the page.

<x:updateActionListener property="#{whatever.id}" value="#{bean.id}" />

If you're using myfaces this worked for me
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

No, my binding is simply the actionListener="#{....}". That being bound to a method isn't working on components that aren't rendered on the first request.
Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
Does immediate="true" help the commandButton? Dumb question, I know.

Sounds like an almost completely different page depending on circumstances. I'm trying to imagine what it looks like.

Can you grab the handle to the component, then add a listener in the backing bean at runtime when enabling happens? Don't know if you can do that with a backing bean listener type method, but you certainly can do it with a listener class.

Good luck with it.

Paul
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ok, what I learned from the MyFaces mailing list is pretty interesting. Basically, when in request scope, although the response phase knows to render the button component, it is out of sync with the server. The server still sees it has non-rendered. Why this is I have no idea and it doesn't make sense. But at least I now know what I want to do isn't really possible without some work arounds.
 
Don't get me started about those stupid light bulbs.
 
subject: Bean request Scope won't Call method
 
Similar Threads
How can I refresh(reset) inputText in a dataTable?
DataTable with CommandLinks
JSF + RichFaces not able to reRender
Action Event
Simple list table