{"id":1399,"date":"2011-07-06T17:16:29","date_gmt":"2011-07-06T17:16:29","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1399"},"modified":"2011-07-26T09:47:46","modified_gmt":"2011-07-26T09:47:46","slug":"faceletsusing-a-custom-tag-interchangeably-instead-of-a-decorator","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1399","title":{"rendered":"Facelets&ndash;using a custom tag interchangeably instead of a Decorator"},"content":{"rendered":"<p><strong><u>Update 26\/7\/2011<\/u><\/strong><\/p>\n<p>Some more points that were omitted or incorrect in the first posting:-<\/p>\n<ul>\n<li>A handy feature with templates\/custom tags is that you can render children of the template\/tag at the call site simply by using a &lt;ui:insert&gt; without a name. You therefore do not need to use a &lt;ui:define&gt; tag in this case, and all children which are not contained in other &lt;ui:define&gt; or &lt;ui:param&gt; tags will be rendered as part of this default &lt;ui:insert&gt;<\/li>\n<li>The statement below that it is not possibly to insert a number of different markup variants in a composite component is incorrect. A composite component can have a number of named facets just like a \u2018real\u2019 JSF component, and these allow markup to be inserted in the same way as &lt;ui:insert&gt;\/&lt;ui:define&gt; does for a template or custom tag.<\/li>\n<\/ul>\n<p><strong><u><\/u><\/strong><\/p>\n<p><strong><u>Original Post<\/u><\/strong><\/p>\n<p>I had a complex decorator which was used for tree browsing. It had a number of ui:inserts for custom markup, plus also a large number of &lt;ui:params&gt; to define EL parameters used within it.<\/p>\n<p>This all worked fine, and even looked quite tidy as all the &lt;ui:params&gt; were listed one per line below each other. However, it was all rather verbose compared to using a custom tag where you would use attributes instead to pass the EL parameters.<\/p>\n<p>It turns out that you can convert a decorator to be a custom tag with no effort as they operate similarly. You merely need to register the xhtml file in a taglib as with any custom tag, and you can then call <em>exactly the same code<\/em> as a custom tag instead of a decorator.<\/p>\n<p>The neat tricks here are that:-<\/p>\n<ul>\n<li>&lt;ui:params&gt; become attributes which are less verbose, but the tag itself does not know any difference and needs no changes. <\/li>\n<li>&lt;ui:insert&gt;\/&lt;ui:define&gt; work perfectly with a custom tag exactly as they do with a decorator. <\/li>\n<\/ul>\n<p>&#160;<\/p>\n<p>Another nice point on this is you can develop custom tags that include pseudo \u2018child markup\u2019 in similar fashion to composite components, by using the &lt;ui:define&gt;s. Providing you do not need the other features of composite components such as retargeting, Ajax etc., custom tags can be very useful where you have a need to insert a number of different markup variants for different flavours of the tag, as you cannot do this so flexibly with a composite component.<\/p>\n<p>The technique of using &lt;ui:inserts&gt; in a custom tag is hinted at somewhat obliquely in Core Javaserver Faces, 3rd Edition, on P196 in the listing of the <em>planet<\/em> custom tag, which contains a &lt;ui:insert&gt; called <em>content1.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update 26\/7\/2011 Some more points that were omitted or incorrect in the first posting:- A handy feature with templates\/custom tags is that you can render children of the template\/tag at the call site simply by using a &lt;ui:insert&gt; without a name. You therefore do not need to use a &lt;ui:define&gt; tag in this case, and [&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":[76,184,16,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1399"}],"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=1399"}],"version-history":[{"count":3,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1399\/revisions"}],"predecessor-version":[{"id":1433,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1399\/revisions\/1433"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}