9

I'm working on building a web page and notice now that I have to press the command button twice. Any command button has the same problem, so I figured I would add and action listener on one of them to see if I could see something.

<h:form id="formP">
    <p:commandButton id="temp" value="photos" actionListener="#{viewBacking.debugBreakpoint()}" action="userPhoto" />
</h:form>

The backing bean has

public void debugBreakpoint() {
    int i = 0;
    i++;
}

Unfortunately, this does help. It hits my breakpoint only after the second press. I suspect that some field somewhere isn't passing validation but I would like some method of detecting what exactly is going wrong - why do I need the second push? Is there some option I can turn on in Glassfish, or something else where I can look at a dump of debug information? I can ignore the dump until everything is stable and then see what exactly is happening when I press the button for the first time.

Is there any such tool which I can use?

Ilan Tal
  • 509
  • 2
  • 8
  • 22
  • add `` to your page so you could see any validation errors – Petr Mensik May 30 '12 at 10:58
  • I added the , which is a good idea in any case. Nothing came up, but I'm not at all sure it is a validation error. Changing the signature of the debugBreakpoint causes it not to hit it at all. The problem is that the first time it doesn't hit the break point and the second time it is correct and legal. – Ilan Tal May 30 '12 at 12:06
  • Is this h:form being rerendered by another h:form? – Elias Dorneles May 30 '12 at 12:13
  • I am using a master template with Then in the center I use . There is a on the master template. Does that make my page in the center rerendered? – Ilan Tal May 30 '12 at 12:34
  • Have you tried other machines and browsers? I just had this happen to me today too, and so far it's local to 10Zig thin clients running Google Chrome. Cannot duplicate on my Thinkpad under either IE or Chrome there. Same OS, etc. – Brian Knoblauch May 30 '12 at 12:40
  • I guess my real question is: is there some sort of dump tool where I can see all the messages going back and forth? I don't know if the relevant message is in Glassfish or in the HTML parser. In any case, I want some way to see what is happening "inside". – Ilan Tal May 30 '12 at 12:44
  • Wow Brian! for you it happens on a specific machine - browser?!? I'm running Linux-Firefox, but I can try chromium. – Ilan Tal May 30 '12 at 12:46
  • Better to use logging than breakpoints to know what is called. Use breakpoints only in the case log is not enough. – Danubian Sailor Jan 25 '13 at 15:58

5 Answers5

14

That can happen when a parent component of the given <h:form> has been rendered/updated by another command button/link with <f:ajax>. The given form will then lose its view state which it would only get back after submitting the form for the first time. Any subsequent submits will then work the usual way. This is caused by a bug in JSF JS API as descibred in JSF issue 790 which is fixed in the upcoming JSF 2.2.

You need to fix the another command button/link with <f:ajax> to explicitly include the client ID of the given <h:form> in the render.

<f:ajax render=":somePanel :formP" />

Another way is to replace this <f:ajax> by a PrimeFaces <p:commandLink> or <p:commandButton> so that you don't need to explicitly include the client ID of all the forms. PrimeFaces's own JS API has namely already incorporated this fix.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC for your answer. I don't have any ajax calls in my code. It has been driving me crazy. I will open another question where I took my code, opened an entirely new project and cut down everything without mercy. The problem still exists. Please look at the new post which I will shortly post. – Ilan Tal May 31 '12 at 07:47
  • Since you confirmed it is an ajax problem in the subsequent post, I will accept the answer. I don't understand where the comes in. I'll keep at it until I get to the bottom of it. Thanks for the help. – Ilan Tal Jun 03 '12 at 10:26
  • Your concrete problem was after all different, you was after all fully navigating by ajax. See also [your follow up question](http://stackoverflow.com/questions/10829690/continuation-of-pressing-button-twice). My answer is elaborated in more detail [here](http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm). – BalusC Jun 03 '12 at 12:27
0

add event="onclick" in your p:commandbutton
I guess that will sort it out.

Addicted
  • 1,694
  • 1
  • 16
  • 24
  • The onclick is worse than actionListener. When I load the page it hits the breakpoint twice (even though I have NOT pressed the button). If I look in the call stack I see Hidden source calls, the top one being NativeMethodAccessorImple.invoke0. Then when I actually hit the button, it doesn't hit my breakpoint. Ugh! – Ilan Tal May 30 '12 at 11:50
  • according to your code it will look for "userPhoto" string outcome to perform the operation. Is that what you want?? – Addicted May 30 '12 at 11:58
  • either try to change actionlistener to action. or give parameter to your bean method as (ActionEvent ev). may that help you. – Addicted May 30 '12 at 12:00
  • Yes, userPhoto is the page I want to navigate to. I chose this button as a simple example. I have both ActionListener for the break point and action to do the navigation. The problem is that it hits neither the first time around and both (legally, the expected behaviour) the second time around. But why do I need 2 pushes? – Ilan Tal May 30 '12 at 12:28
0

or you can add this ajax="false" property in your commandButton

<p:commandButton ajax="false" action="#{userController.create}" value="#{bundle.CreateUserSaveLink}"></p:commandButton>
F25rT
  • 114
  • 1
  • 10
0

I ran into the same issue. The solution was simple, instead of having both an actionListener and an action, just convert the actionListener method to return a string to where you want to navigate to and use it as the method for the action (and don't have an actionListener).

In simple terms: only use an action (do not use an actionListener on a commandButton that is submitting a form).

Mithel
  • 1
  • 1
0

Please check your binding with bean.

bean fields should be String or non primitive.

oɔɯǝɹ
  • 7,219
  • 7
  • 58
  • 69
Shahid
  • 1