0

I have a very simple xhtml file where a panelGroup containing a commandButton is added to the page on clicking toggle button but this dynamically added commandButton fails to execute its actionlistener on being clicked.

Complete code below:

<?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://java.sun.com/jsf/html" 
      xmlns:p="http://primefaces.org/ui">

    <h:head>
    </h:head>
    <h:body>
        <h:panelGroup id="checkDyna">
            <h:panelGroup rendered="#{listRetriever.booleanStatus}" >
                <h:form>            
                    <p:commandButton value="check" process="@all" actionListener="#{listRetriever.xx()}"/>
                </h:form>
            </h:panelGroup>
        </h:panelGroup>
        <h:form>
            <p:commandButton value="Toggle" actionListener="#{listRetriever.toggleBooleanStatus()}" update=":checkDyna"/>
        </h:form>

    </h:body>
</html>

Bean

@ManagedBean(name = "listRetriever")
@RequestScoped
public class ListRetriever implements Serializable {

    private boolean booleanStatus;        

    public void toggleBooleanStatus(){
        if (!booleanStatus)
            booleanStatus=true;
    }

    public void xx(){
        System.out.println("Invoked***");
    }

    public boolean isBooleanStatus() {
        return booleanStatus;
    }

    public void setBooleanStatus(boolean booleanStatus) {
        this.booleanStatus = booleanStatus;
    }

}

On removing rendered="#{listRetriever.booleanStatus}" actionlistener is successfully invoked.

On making the bean ViewScoped too the problem is eliminated but I dont want to make it wider than RequestScoped.

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
  • possible duplicate of [h:commandLink / h:commandButton is not being invoked](http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked) – BalusC Jun 22 '12 at 04:58

1 Answers1

0

I had this p:commandButton within a conditionally rendered panel whose conditional expression for rendering was evaluating to false while I was trying to execute the actionlistener. This was the cause of actionlistener not getting executed.

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
  • 1
    I thought that you already know that. It's obvious enough as placing the bean in the view scope solves the problem. Your sole question seemed to boil down to how to achieve it anyway without using the view scope. – BalusC Jun 22 '12 at 04:58
  • yes I realised that after checking it with @viewscoped & seeing your answer at question: [h:commandLink / h:commandButton is not being invoked](http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked). Thanks to you for that great answer! – Rajat Gupta Jun 22 '12 at 11:57