{"id":1392,"date":"2011-07-06T15:47:29","date_gmt":"2011-07-06T15:47:29","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1392"},"modified":"2011-07-06T15:47:29","modified_gmt":"2011-07-06T15:47:29","slug":"optionally-including-primefaces-pdatatable-columns","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1392","title":{"rendered":"Optionally including Primefaces &lt;p:dataTable&gt; Columns"},"content":{"rendered":"<p>This can be done e.g. by a Facelets Decorator using &lt;ui:insert&gt; and I have used this in a number of places.<\/p>\n<p>However, in one case, I wanted to make a complex treeBrowser custom tag switchable between editable mode and readonly using just a single flag passed as an attribute. Note that I did not want to switch it dynamically at run time \u2013 I just re-used the tag in a number of places and some were editable and some were not. As this switch involved a number of changes in the tag, it was convenient to drive them all from a single flag.<\/p>\n<p>In addition, whilst I could have used a decorator for this, I already had 2 versions of the tag each decorating a base version, where each version was used to browse completely different tree structured data in the application which was all handled polymorphically.&#160; Using decorators for readonly\/editable as well would have multiplied up the variants to 4, which was undesirable. By using a single EL flag, I was able to make all the switching entirely in the base custom tag which was a real help here.<\/p>\n<p><strong><em>Anyway<\/em><\/strong> \u2013 to discuss the real point of the post \u2013 to achieve my goal I needed to conditionally include columns for a &lt;p:dataTable&gt;. Using &lt;ui:fragment&gt; to do this does not work as &lt;ui:fragment&gt; creates a new component in the JSF tree which is not a column, and &lt;p:dataTable&gt; ignores any children that are not columns. Whilst there are ways using composite components to indicate with interface properties the precise Class type that the component appears to be, fooling &lt;p:dataTable&gt; by making it look like a column does not work \u2013 I tried this and it failed, and there are posts on the Primefaces forum citing the same issue.<\/p>\n<p>The simple solution was to use &lt;c:if&gt; to conditionally include columns. This eventually worked correctly, once I had fixed a particularly nasty incorrect JSTL namespace issue which is fully described in <a href=\"http:\/\/salientsoft.co.uk\/?p=1069\"><strong>this post here<\/strong><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This can be done e.g. by a Facelets Decorator using &lt;ui:insert&gt; and I have used this in a number of places. However, in one case, I wanted to make a complex treeBrowser custom tag switchable between editable mode and readonly using just a single flag passed as an attribute. Note that I did not want [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[40,184,112,16],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1392"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1392"}],"version-history":[{"count":0,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1392\/revisions"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}