title: Hide or show Subreport
body: <p>I have a requirement where i need to show or hide <em>subreport</em> based on user selection.</p>
  
  <p>Say I have a Main report and two sub reports: <em>sub1</em> and <em>sub2</em>.</p>
  
  <p>User selects to show only <em>sub1</em>. The boolean value will be sent through <em>Java</em>.</p>
  
  <p>I need to show main report with <em>sub1</em> in it and hide <em>sub2</em>.</p>
  
  <p>I tried <code>&lt;printwhenexpression&gt;</code> but no matter what it shows only main report.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;subreport&gt;
      &lt;reportElement uuid="25895ea2-ed3d-49d2-997b-f0e4e6e304a3" mode="Transparent" x="0" y="0" width="555" height="38"&gt;
          &lt;printWhenExpression&gt;&lt;![CDATA[($P{flag}==Boolean.TRUE)]]&gt;&lt;/printWhenExpression&gt;
      &lt;/reportElement&gt;
      &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
      &lt;subreportExpression&gt;&lt;![CDATA[$P{SUBREPORT_DIR} + "subreport1.jasper"]]&gt;&lt;/subreportExpression&gt;
  &lt;/subreport&gt;
  </code></pre>