0

The following simplificated Code is working when I set ajax="false". With ajax="true" the second commandButton don't calls personPM.commitEditPerson() when pushed after was updated by Button1 or Button2.

Can someone help me whats wrong here? Because it seems to be not easy to solve, I add the whole code that it can be easily reproduced (JSF 2.2, Primefaces is 3.5, GlassFish 4.0):

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
            <h:form id="f1">                    
                <p:commandButton id="Button1" update=":neuePerson" value="Neue Person" action="#{testPM.setCurrentPerson()}"/>
            </h:form>

            <h:panelGroup id="neuePerson">
                <h:form id="f2" >
                    <p:commandButton id="Button2" update=":neuePerson" value="Übernehmen" action="#{testPM.commitEditPerson()}"/>
                </h:form>
            </h:panelGroup>
    </h:body>
</html>

Session Scoped Bean TestPM.java:

package at.feimas.administration.presentation;

import java.util.logging.Level;
import java.util.logging.Logger;

public class TestPM {

    private String currentPerson;
    private String firstName;

    private static final Logger logger = Logger.getLogger(TestPM.class.getName());

    public void setCurrentPerson() {
        logger.log(Level.INFO, "New Person");
    }    
    public void commitEditPerson(){
        logger.log(Level.INFO, "Edit Person");
    }    
}
timmornYE
  • 698
  • 2
  • 8
  • 22
  • Is this your actual code? Are there any validators on fields in the second form? Check the JavaScript-Console to see if there is actually a request going out to the server. BTW `ajax=true` is the default value. – user1983983 Jul 30 '13 at 10:09
  • Not sure if this fixes the problem, but you are using `action` when `actionListener` should be used: http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener – Lester Jul 30 '13 at 10:12
  • @user1983983 Yes, this is the actual code. There are no validators. The JavaScript Console tells me that a request is going to the server. But personPM.commitEditPerson() is not called (I have implemented a log message). – timmornYE Jul 30 '13 at 11:03
  • @Lester I tried it, but it didn't change anything: personPM.commitEditPerson() is not called. – timmornYE Jul 30 '13 at 11:04
  • possible duplicate of [JSF commandButton works on second click](http://stackoverflow.com/questions/11408130/jsf-commandbutton-works-on-second-click), related: http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Jul 30 '13 at 11:28
  • Sounds somewhat related, but using the js didn't change anything. – timmornYE Jul 30 '13 at 11:42
  • Your code works for me. Maybe a config problem? You have a beans.xml and stuff? – Lester Jul 30 '13 at 12:25
  • Thank you for testing. I have added all xml. You have pressed button 1, then button 2 appeared and then pressed button 2 and the log message appeared? – timmornYE Jul 30 '13 at 12:36
  • That's the way it worked for me. At first sight `bean-discovery-mode="annotated"` in beans.xml looks strange as your bean has no annotation. – Lester Jul 30 '13 at 12:43
  • Thanks again, but setting to bean-discovery-mode="all" didn't change anything. Same behaviour: Clicking "Neue Person" gives: "New Person" in log and clicking "übernehmen" gives nothing. Reload the page or set ajax="false" and it is working. Have you the same version of jsf? Primefaces is 3.5. I use GlassFish 4.0. – timmornYE Jul 30 '13 at 20:36
  • The Problem is definitely the "update" action. When I delete the "rendered" element the button is still blocked in the component which was updated. When I delete the "update" elements it works. But I need the update elements. Any ideas? – timmornYE Jul 30 '13 at 20:53
  • I tried with JSF Mojarra 2.1.7 (and since today 2.1.24) and PF 3.5 on JBoss 7.1.1. If you CAN access the bean and open the page in your browser, I have no idea what else could go wrong, as the code works for me as it is. So I suppose it's not the code. You don't get any error messages by coincidence? – Lester Jul 31 '13 at 09:45
  • No, no error. I also tried Chrome, IE and Firefox - everywhere the same. As you can see I reduced the code now to the minimum. As soon as a component is updated, the commandButton in this component is not firing the actionListener. I tried now to make a completely new project and ran it on Tomcat 7.0.34.0 -> exactly the same result. I can not believe why this should only happen in my setup? – timmornYE Jul 31 '13 at 11:10
  • @Lester can you have a look at my solution? I can not really understand why this didn't happen to you. It would be interesting. – timmornYE Aug 01 '13 at 11:17

1 Answers1

0

The problem is caused by a version mismatch PF 3.5 is not ready for JSF 2.2! I used PF snapshot 4.0 and it worked.

This code should show the whole problem and how to solve it with PF 3.5 and JSD 2.2, but I strongly suggest to use versions which work together!:

<h:body>
    <h:form id="f1">                    
        <p:commandButton id="Button1" update=":f2:buttonpanel2" value="New Person" actionListener="#{testPM.setFirstName}"/>
    </h:form>

    <h:panelGroup id="buttonpanel1">
        <h:form id="f2">      
            <h:panelGroup id="buttonpanel2">
                <h:outputText value="#{testPM.firstName}" id="firstName"/>                
                <p:commandButton id="Button2" update=":f2:buttonpanel2" value="Apply" actionListener="#{testPM.commitEditPerson}"/>
            </h:panelGroup>
        </h:form>          
    </h:panelGroup>
</h:body>

If the buttons use 'update=":buttonpanel1"' this leads to the behaviour I posted here in the question: As soon the update takes place, form f2 doesn't work anymore. If the buttons use 'update=":f2:buttonpanel2"' everything works as expected.

timmornYE
  • 698
  • 2
  • 8
  • 22
  • Unfortunately I do not have any explanation for this. All versions work for me. :/ When I replace `Button2`'s `update`-attribute's value with ":buttonpanel1" it still works perfectly fine. – Lester Aug 01 '13 at 15:31
  • Ok, thanks for looking again. Then this will stay a mystery. I hope that if someone else faces this problem, it still helps. – timmornYE Aug 02 '13 at 12:19
  • 1
    I have the solution: It is definitely a version mismatch. PF 3.5 is not ready for JSF 2.2. I used now PF 4 Snapshot and it works also when updating form. – timmornYE Aug 05 '13 at 12:02