Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean request Scope won't Call method

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic