Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

have to press command button twice

Tags:

jsf

primefaces

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?

like image 907
Ilan Tal Avatar asked May 30 '12 10:05

Ilan Tal


1 Answers

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.

like image 142
BalusC Avatar answered Oct 17 '22 17:10

BalusC