Sunday, February 3, 2008

JSF does not call action in managed bean

In the few previous days I had the same problem more than once. For some reason, action in managed bean was not called from JSF page. I was searching through the Internet but couldn't find any real help although more than one person had the same or very similar problem.

Here is situation I had. There is JSF page with the form, some input fields and button that should call action on managed bean. When you click the button action should be called but nothing happens. There is no error displayed nor you can find out where the call is lost. After some investigation it turned out that this appear each time when JSF does not succeed to map values form page to values in managed bean. But there is no clue which values are not binded correctly. I know this is validation and conversion problem and in some cases immediate="true" should solve the problem but in my case even that didn't help.

So how do I solve such situations. There is no straightforward solution for this but following should work in the most of the cases:
Remove field by field in your JSF page. Then redeploy application and try if your method works. Maybe even you need to remove combination of fields to make your action being called.
When you find out which field(s) are cause of the problems you can concentrate on those fields and solve the problem.

What I found out in my cases was:
  • Once setter I used was not of void type but returned some value. JSF didn't accept this return value
  • Once setter I used was throwing RunTimeException that was not handled correctly
Anyway, action not being called without any message or stacktrace displayed can be very annoying. It is very hard (at least for me) to find out what is happening and I hope that this simple but time consuming process will help somebody else as it did help me in few situations.

24 comments:

Anonymous said...

Thank you very much. It was a big problem for me to fix it in a complex page without any errors dumped

Anonymous said...

Its amazing this happens in JSF its a big time waster

Unknown said...

That makes me think Java sucks...

jan said...

@matheus
Because of the bug in a web framework based on Java I wouldn't come to the conclusion that Java sucks.

Unknown said...

Dudes, I agree there should be better feedback from the JSF implementation you're using.
However, the framework relies on Java Beans. There are specific conventions for what constitutes a property on a bean. A setter that doesn't return void is not a bean property and therefore won't be used as a property.
Not sure if your JSF impl will tell you when it can't find properties, but the h:messages tag is supposed to provide JSF error feedback.
Matheus, this has nothing to do with Java. Your comment is the equivalent of saying computers suck.

Anonymous said...

Same problem. Drives me up a wall. Make me think JBoss is a toy. We should at least see an error message in the log.

Shivaji said...

Yupe there should be some logging msgs even to track the flow atleast. i used the debug to track out the issue and came to see the contraol returning back driectly from JSF jars itself. Even no logs...

Unknown said...

I know this posting is old, but in my case I had a rendered attribute on my commandButton. If the rendered attribute resolves to false when the commandButton is clicked the defined action does not get called.

Anonymous said...

Hi,

Thanks for the blog.. The way I see jsf *&^*%&&^ is modelled after .net crap and this wastes tonnes and tonnes of time... and if you are stuck, then good luck.. just like .net you will be lucky to get any help.

Such a waste of time. Spring or even Struts was so swift and cleaner. Yes, jsf saves (again if you are lucky) some time in sorting tables and all those craps... but jsf is not worth any effort... it is big shame on open source and people who write code for jsf should be sent to MS corp for testing.
.......

Anonymous said...

Hey Jan,
Thanks for this info.

Page said...

If this helps anyone, I had this "action not being called without any error message" thing because I declared the myfaces extension filter in web.xml but somehow forgot to map it to jsf servlet. My form with a tag didnt call the backing beans action nor raised any exceptions or log messages. Took me like an hour. It was dreadfull.

Venk said...

Another reason this issue can happen (that we came to know spending few hours) is when commandButton is placed inside the verbatim tag...

Anonymous said...

Thank you so much !! this helped solve my problem. I had spent close to 4 hours trying to figure it out before I saw your post.

Johan said...

I've had the same problem. A non-working button, because of an action that wasn't called. In my case, it turned out that the problem was that the actionbutton had some properties that read from a request-scope-bean (rendered, value) Since the bean had request scope, the values were lost before i clicked the actual button. (after rendering the page with the button on it) After changing the bean scope to session, the problem disappeared.

Anonymous said...

Thanks, it was informative and hlepd me fix a bug.

sasmit said...

solved my problem too.. same problem as jan, bean had some properties that were getting lost when scope was set to request. Changed the scope back to session and it worked like a charm. Extremely annoying bug in jsf though hope this improves with newer releases.

Özlem Gürses said...

This solved my problem. Thank you very much. I've searched about this problem for a long time and this information is very helpful for me.

Reda said...

it took me a hours, thanks a lot for your post

Anonymous said...

Thanks a lot. This helps. Searched many other post for this problem but none of them helped. You are the best!

Anonymous said...

Thanks for you help!!
Roberto

Fernando said...

The type attribute must be "submit" or "reset".
The "button" type works for javascript i guess...

Fernando said...

The type attribute must be "submit" or "reset".
The "button" type works for javascript i guess...

Anonymous said...

Man...thanks you very much!!

Anonymous said...

Thanks.. that helped me when I was trying everything and failing.