0

I thought this would be easy but I just cannot get it. I have a drop down and based on selection, I should be able to show/Hide another drop down based on a boolean. By default the boolean is false and only when it is true should the second drop down be rendered:

My page:

 <h:outputLabel value="Select Report: "/>
                                    <p:selectOneMenu value="#{daily.reportname}" id="sector"  style="width: 250px;"> 
                                        <f:selectItem itemLabel="ALL" itemValue="ALL" />
                                        <f:selectItems value="#{daily.reportType()}"/>
                                        <p:ajax  event="change" update="branchrender"  listener="#{daily.selectedReport()}" />
                                    </p:selectOneMenu>
 <h:panelGroup  id="branchrender" rendered="#{daily.showBranchDimension}">
                                        <h:outputText value="Branch" />
                                        <p:selectOneMenu value="#{accounts.branchs}" id="branch"  style="width: 250px;"> 
                                            <f:selectItem itemLabel="ALL" itemValue="ALL" />
                                            <f:selectItems value="#{dimensions.branchCode()}"/>                    
                                        </p:selectOneMenu>
                                    </h:panelGroup>

My selected report Method:

public void selectedReport() {
        if (reportname.startsWith("cust_")) {
            custrepname = reportname;
            useBranch = pr.getCustRepProperties(custrepname + ".bi").getProperty("bi.useBranchDim");
            showBranchDimension = useBranch.equalsIgnoreCase("true");
            System.out.println("HERE: " + showBranchDimension);
        } else {
            custrepname = null;
        }

    }

showBranchDimension is a boolean having getter and setter:

public boolean isShowBranchDimension() {
        return showBranchDimension;
    }

    public void setShowBranchDimension(boolean showBranchDimension) {
        this.showBranchDimension = showBranchDimension;
    }

Am I missing something? The System.out.println prints true but the component is NOT rendered.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168
  • 1
    Check the scope of your bean in relation to the annotation that makes it a managed bean. And learn about rendering previously not rendered components: http://stackoverflow.com/questions/9010734/why-do-i-need-to-nest-a-component-with-rendered-some-in-another-component-w – Kukeltje Feb 02 '16 at 12:49

2 Answers2

2

You have to make the rendered component a rendered free because it must be exist when you submit the ajax request to server add another container to branchrender and move the rendered id to it

<h:panelGroup  id="branchrender">
     <h:panelGroup   rendered="#{daily.showBranchDimension}">
                                        <h:outputText value="Branch" />
                                        <p:selectOneMenu value="#{accounts.branchs}" id="branch"  style="width: 250px;"> 
                                            <f:selectItem itemLabel="ALL" itemValue="ALL" />
                                            <f:selectItems value="#{dimensions.branchCode()}"/>                    
                                        </p:selectOneMenu>
      </h:panelGroup> 
</h:panelGroup>

See more about this.

Community
  • 1
  • 1
Youans
  • 4,801
  • 1
  • 31
  • 57
0

I think problem could be with the way your implemented the p:ajax component. See the comments of p:ajax listener method not invoked.

Community
  • 1
  • 1
cdaiga
  • 4,861
  • 3
  • 22
  • 42