{"id":1428,"date":"2011-07-25T11:35:19","date_gmt":"2011-07-25T11:35:19","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1428"},"modified":"2011-07-25T11:38:05","modified_gmt":"2011-07-25T11:38:05","slug":"primefaces-ppanel-component","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1428","title":{"rendered":"Using the Primefaces p:panel component"},"content":{"rendered":"<p>This post details some tips discovered whilst experimenting with p:panel.<\/p>\n<p>1\/ The toggle button on the right hand side of the panel is rendered with <em>ui-state-default<\/em>. This does not look attractive with some themes \u2013 it often looks like a bit of a zit due to the background on the thick plus sign icon. I noticed that the dialog component p:dialog does not render its close icon in the header with <em>ui-state-default,<\/em>&#160; and this looks much more attractive as the surrounding highlight on the icon only shows on hover.<\/p>\n<p>This can be applied to p:panel by removing the <em>ui-state-default<\/em> class from the anchor tags around the icons on the panel header. The following example jQuery performs this (in my case, the panelDivId argument is the ID of an h:paneGroup\/div surrounding the panel:-<\/p>\n<blockquote>\n<p>function ss_PanelFixIcons(panelDivId) {      <br \/>&#160;&#160;&#160; var escapedPanelDivId = panelDivId.replace(\/:\/g, &#8216;\\\\3A &#8216;);       <br \/>&#160;&#160;&#160; var panelIcons = jQuery(&#8216;div#&#8217; + escapedPanelDivId + &#8216; div.ui-panel-titlebar &gt; a.ui-panel-titlebar-icon&#8217;);       <br \/>&#160;&#160;&#160; panelIcons.removeClass(&#8216;ui-state-default&#8217;);       <br \/>}<\/p>\n<\/blockquote>\n<p>&#160;<\/p>\n<p>2\/ It would be nice to be able to explicitly expand and collapse the panel as well as to just toggle it. In fact the panel widget does expose its current state via its <em>cfg <\/em>property, although this is not publicly documented. The following example functions use this to provide explict expand, collapse, and set to passed boolean state functions. In addition a function is provided to get the current panel state:-<\/p>\n<blockquote>\n<p>function ss_PanelExpand(widgetVar) {      <br \/>&#160;&#160;&#160; if (widgetVar.cfg.collapsed) {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; widgetVar.toggle();       <br \/>&#160;&#160;&#160; }       <br \/>}<\/p>\n<p>function ss_PanelCollapse(widgetVar) {      <br \/>&#160;&#160;&#160; if (!widgetVar.cfg.collapsed) {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; widgetVar.toggle();       <br \/>&#160;&#160;&#160; }       <br \/>}<\/p>\n<p>function ss_PanelSetCollapsed(widgetVar, state) {      <br \/>&#160;&#160;&#160; if (!widgetVar.cfg.collapsed == state) {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; widgetVar.toggle();       <br \/>&#160;&#160;&#160; }&#160;&#160;&#160; <br \/>}<\/p>\n<p>function ss_PanelGetCollapsed(widgetVar) {      <br \/>&#160;&#160;&#160; return widgetVar.cfg.collapsed;       <br \/>}<\/p>\n<\/blockquote>\n<p>&#160;<\/p>\n<p>3\/ A query came up on the Primefaces forum on how to lazy load the panel, as it eagerly loads and the expand\/collapse is all done client side. The post is available <a href=\"http:\/\/primefaces.prime.com.tr\/forum\/viewtopic.php?p=23156\"><strong>here<\/strong><\/a>. the solution is straightforward:-<\/p>\n<ul>\n<li>Use a toggleListener to update a renderPanel property to true if the panel state from the event was <em>visible<\/em>, and false if it was <em>hidden.<\/em> <\/li>\n<li>Then conditionally render a content h:panelGroup inside the panel, using the above property as the <em>rendered<\/em> property. <\/li>\n<li>One issue with this is that the actual panel toggle occurs before the ajax update of the panel not after, so with the slide toggle effect on (say with toggleSpeed=\u201d1000\u201d), you see an empty sliding toggle first, then a non sliding ajax update. In this case it is best to turn off the slide effect with <em>toggleSpeed=\u201d0\u201d.<\/em> If you use another button to toggle the panel you can get around this, as the onComplete event for the button can toggle the panel (via its widget\/ as per the above JavaScript), and this happens after the Ajax to render the panel. In practice you would have to somehow overlay the standard toggle button with another one of your own, or manually disable the standard one via CSS, as if you set <em>toggleable=\u201dfalse\u201d<\/em> for the panel this completely disables toggling via the widget as well as removing the toggle button. <\/li>\n<li>It is probably not worth the trouble of trying to get sliding to work if you are lazy loading. Note that when I tried some older\/slow machines the slide effect rendered poorly anyway, so this should also be born in mind. <\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This post details some tips discovered whilst experimenting with p:panel. 1\/ The toggle button on the right hand side of the panel is rendered with ui-state-default. This does not look attractive with some themes \u2013 it often looks like a bit of a zit due to the background on the thick plus sign icon. I [&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":[119,184,112,16,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1428"}],"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=1428"}],"version-history":[{"count":2,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1428\/revisions"}],"predecessor-version":[{"id":1430,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1428\/revisions\/1430"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}