• Post Reply Bookmark Topic Watch Topic
  • New Topic

h:commandButton doesn't work on first click

 
Cora Bohne
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JSF and I have the following code:



When I click on the commandButton with the value "Hinzuf├╝gen" the action "createAgendaEntry" won't be called. Only when I click the second time, it happens. I tried many solutions with panelGroups etc. But nothing worked. Is there any solution for it?
 
Greg Charles
Sheriff
Posts: 3010
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cora, and welcome to Java Ranch!

Do you have browser debugging tools available? I'm partial to Firebug on Firefox, but there are many other options. It would be interesting to see if the request is being sent by the browser to the server at all on the first click. I'm not sure why it wouldn't be though. The only thing that jumps out at me is that on JSF tags, you should use "styleClass" as an attribute rather than "class". Just using "class" might interfere with JSF's rendering. I doubt that's the main problem here, but it's worth a try.
 
Cora Bohne
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg!

Thanks for your reply!
Using styleClass didn't change anything. But I found out that it works when I open only this page.
The code above is in an XHTML-file. And this file is inside another XHTML included this way:



Could it have anything to do with the focus?

A post will be sent. At the first and the second time.

 
Cora Bohne
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved it.
This answer helped me: http://stackoverflow.com/questions/11408130/hcommandbutton-hcommandlink-does-not-work-on-first-click-works-only-on-second#answers-header
And I had to put the some.js it in a folder. Otherwise it didn't work.
 
Tim Holloway
Bartender
Posts: 18417
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pedantic note: JSF backing beans are never Controllers. In JSF, the Controllers are pre-supplied and you don't write your own. You only need to write Models and Views. The backing beans are Models. Action methods are not Controller logic. they're (non-MVC) business methods. So naming a backing bean "xxxxController" is not good practice.

I'm not impressed by the StackOverflow example. They're passing parameters in action methods, which isn't how action methods were intended to work (it tends to pollute the MVC Separation of Concerns discipline). The original example appears to be based on failure of a control which isn't defined in the visible form and the included file isn't shown so I cannot tell if there was a separate form in the included file.

They do reference another topic which mentions the actual bug.

As a general rule, when AJAX re-rendering doesn't seem to work correctly, I have found that expanding the re-rendered area will usually help. Re-rendering anything that has JavaScript code in it can be tricky, though, especially if the code was expected to run after the re-rendering, since the code that's re-rendered might have been changed by the AJAX listener code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!