{"id":4476,"date":"2012-03-08T13:08:35","date_gmt":"2012-03-08T18:08:35","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=4476"},"modified":"2012-06-20T15:24:53","modified_gmt":"2012-06-20T20:24:53","slug":"facelet-composite-components","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=4476","title":{"rendered":"Facelet Composite Components"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Setup_Test_Project\">Setup Test Project<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Create_a_Test_Bean\">Create a Test Bean<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Create_a_New_Facelet_Composite_Component\">Create a New Facelet Composite Component<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Setup_testcc-taglib.xml\">Setup testcc-taglib.xml<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Test_Composite_Component\">Test Composite Component<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Test\">Test<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Debug\">Debug<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/jsf2_trinidiad_testcc_folders.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/jsf2_trinidiad_testcc_folders-150x300.jpg\" alt=\"\" title=\"jsf2_trinidiad_testcc_folders\" width=\"150\" height=\"300\" class=\"aligncenter size-medium wp-image-4483\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/jsf2_trinidiad_testcc_folders-150x300.jpg 150w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/jsf2_trinidiad_testcc_folders.jpg 266w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><\/h6><\/span>\n<span id=\"Setup_Test_Project\"><h3>Setup Test Project<\/h3><\/span>\n<p>* Follow<a href=\"?p=3813\"> this post<\/a> to setup a dynamic web project using MyFaces Trinidad in Eclipse. You can download the <a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2011\/12\/jsf2.myfaces2.trinidad2.one_1.zip\">sample code<\/a> to begin with.<br \/>\n* Add CDI\/WELD support to the project. See <a href=\"?p=4373\">this post<\/a> for details.<br \/>\n&#8211; Add weld.jar to build path and assembly path<br \/>\n&#8211; Add weld listener to web.xml<br \/>\n&#8211; Add beans.xml to src\/MEATA-INF<\/p>\n<span id=\"Create_a_Test_Bean\"><h3>Create a Test Bean<\/h3><\/span>\n<p>* Create a new package named test<br \/>\n* Create a new Java class in test package named <strong>TestBean<\/strong><\/p>\n<pre lang=\"java\">package test;\r\n\r\nimport javax.enterprise.context.RequestScoped;\r\nimport javax.inject.Named;\r\n\r\n@Named\r\n@RequestScoped\r\npublic class TestBean {\r\n\tpublic String getTitle() {\r\n\t\treturn \"Test Bean\";\r\n\t}\r\n\r\n\tprivate String val;\r\n\tprivate String[] vals;\r\n\t\r\n\tpublic String[] getVals() {\r\n\t\treturn vals;\r\n\t}\r\n\r\n\tpublic void setVals(String[] vals) {\r\n\t\tthis.vals = vals;\r\n\t}\r\n\r\n\tpublic String getVal() {\r\n\t\treturn val;\r\n\t}\r\n\r\n\tpublic void setVal(String val) {\r\n\t\tthis.val = val;\r\n\t}\r\n\r\n\tpublic String getStr(){\r\n\t\treturn \"A string\";\r\n\t}\r\n\r\n\tpublic String[] getStrs(){\r\n\t\tString[] tmp = new String[3];\r\n\t\ttmp[0] = \"String one\";\r\n\t\ttmp[1] = \"String two\";\r\n\t\ttmp[2] = \"String three\";\r\n\t\treturn tmp;\r\n\t}\r\n}\r\n\r\n<\/pre>\n<span id=\"Create_a_New_Facelet_Composite_Component\"><h3>Create a New Facelet Composite Component<\/h3><\/span>\n<p>* Add a new folder named <strong>faceletlib<\/strong> under <em>WEB-INF<\/em> directory<br \/>\n* Add a new xhtml file named<strong> testccFace.xhtml<\/strong> in the <em>faceletlib <\/em>directory. Note that we introduced two new variables in the composite whose values can be passed in at run time: <strong>testcc_id<\/strong> and <strong>testcc_bean<\/strong><\/p>\n<pre lang=\"xml\">\r\n<ui:composition xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"\r\n\txmlns:ui=\"http:\/\/java.sun.com\/jsf\/facelets\"\r\n\txmlns:h=\"http:\/\/java.sun.com\/jsf\/html\"\r\n\txmlns:f=\"http:\/\/java.sun.com\/jsf\/core\"\r\n\txmlns:trh=\"http:\/\/myfaces.apache.org\/trinidad\/html\"\r\n\txmlns:tr=\"http:\/\/myfaces.apache.org\/trinidad\"\r\n\txmlns:c=\"http:\/\/java.sun.com\/jstl\/core\">\r\n\r\n\t<tr:panelLabelAndMessage for=\"#{testcc_id}\">\r\n\t\t<f:facet name=\"help\">\r\n\t\t\t<tr:outputText value=\"Pick a date\" \/>\r\n\t\t<\/f:facet>\r\n\t\t<tr:inputDate id=\"#{testcc_id}\" simple=\"true\" \/>\r\n\t<\/tr:panelLabelAndMessage>\r\n\r\n\t<tr:spacer height=\"15\" \/>\r\n\r\n\t<tr:panelFormLayout>\r\n\t\t<!-- A bunch of form components -->\r\n\t\t<tr:selectOneChoice value=\"#{testcc_bean.val}\" required=\"true\"\r\n\t\t\tlabel=\"Select One Option:\">\r\n\t\t\t<f:selectItem itemLabel=\"Option1\" itemValue=\"1\" \/>\r\n\t\t\t<f:selectItem itemLabel=\"Option1\" itemValue=\"2\" \/>\r\n\t\t\t<f:selectItem itemLabel=\"Option1\" itemValue=\"3\" \/>\r\n\t\t<\/tr:selectOneChoice>\r\n\r\n\t\t<tr:selectManyCheckbox value=\"#{testcc_bean.vals}\" required=\"true\"\r\n\t\t\tlabel=\"Select many options:\">\r\n\t\t\t<f:selectItem itemLabel=\"Option1\" itemValue=\"1\" \/>\r\n\t\t\t<f:selectItem itemLabel=\"Option1\" itemValue=\"2\" \/>\r\n\t\t\t<f:selectItem itemLabel=\"Option1\" itemValue=\"3\" \/>\r\n\t\t<\/tr:selectManyCheckbox>\r\n\r\n\t<\/tr:panelFormLayout>\r\n<\/ui:composition>\r\n\r\n<\/pre>\n<span id=\"Setup_testcc-taglib.xml\"><h3>Setup testcc-taglib.xml<\/h3><\/span>\n<p>* Create a new xml file named <strong>testcc-taglib.xml<\/strong> in the <em>WEB-INF<\/em> directory<br \/>\n* Define a namespace for the new facelet taglib, e.g. <strong>http:\/\/www.testcc.com\/facelets<\/strong><br \/>\n* Enter the tag-name and point source to testccFace.xhtml file<\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\"?>\r\n<!DOCTYPE facelet-taglib PUBLIC\r\n\"-\/\/Sun Microsystems, Inc.\/\/DTD Facelet Taglib 1.0\/\/EN\"\r\n\"http:\/\/java.sun.com\/dtd\/facelet-taglib_1_0.dtd\">\r\n<facelet-taglib>\r\n\t<namespace>http:\/\/www.testcc.com\/facelets<\/namespace>\r\n\t<tag>\r\n\t\t<tag-name>testcc<\/tag-name>\r\n\t\t<source>faceletlib\/testccFace.xhtml<\/source>\r\n\t<\/tag>\r\n<\/facelet-taglib>\r\n<\/pre>\n<p>* Declare new facelet tag lib in web.xml:<\/p>\n<pre lang=\"xml\">\r\n  <!--\r\n      =================\r\n  \t\tFacelet Tag library\r\n      =================\r\n  -->  \r\n  <context-param>\r\n    <param-name>facelets.LIBRARIES<\/param-name>\r\n    <param-value>\/WEB-INF\/testcc-taglib.xml<\/param-value>\r\n  <\/context-param>\r\n<\/pre>\n<span id=\"Test_Composite_Component\"><h3>Test Composite Component<\/h3><\/span>\n<p>* Add a new folder named <strong>testcc<\/strong> (read test composite component) under <em>WebContent<\/em> directory<br \/>\n* Add a new xhtml page named <strong>testccForm.xhtml<\/strong><br \/>\n* Add <em>testcc<\/em> namespace in order to use the new taglib: <em>xmlns:tcc=&#8221;http:\/\/www.testcc.com\/facelets&#8221;<\/em><br \/>\n* Use the tablib and pass in values for the two variables, i.e.<em> testcc_id<\/em> and <em>testcc_bean<\/em>:<\/p>\n<pre lang=\"xml\">\r\n<ui:composition xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"\r\n\txmlns:ui=\"http:\/\/java.sun.com\/jsf\/facelets\"\r\n\txmlns:h=\"http:\/\/java.sun.com\/jsf\/html\"\r\n\txmlns:f=\"http:\/\/java.sun.com\/jsf\/core\"\r\n\txmlns:tr=\"http:\/\/myfaces.apache.org\/trinidad\"\r\n\txmlns:tcc=\"http:\/\/www.testcc.com\/facelets\">\r\n\r\n  Sample Form: #{testBean.title}\r\n\t<tr:form>\r\n\t\t<tr:messages styleClass=\"message\" \/>\r\n\t\t<tcc:testcc testcc_id=\"id1\" testcc_bean=\"#{testBean}\">\r\n\t\t<\/tcc:testcc>\r\n\t<\/tr:form>\r\n\r\n<\/ui:composition>\r\n\r\n<\/pre>\n<p>* Add a new xhtml page named <strong>testcc.xhtml<\/strong> and include testccForm.xhtml<\/p>\n<pre lang=\"xml\">\r\n<ui:composition xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"\r\n\txmlns:ui=\"http:\/\/java.sun.com\/jsf\/facelets\"\r\n\ttemplate=\"\/templates\/template1.xhtml\"\r\n\txmlns:tr=\"http:\/\/myfaces.apache.org\/trinidad\"\r\n\txmlns:h=\"http:\/\/java.sun.com\/jsf\/html\">\r\n\r\n\t<ui:define name=\"body\">\r\n        <ui:include src=\"testccForm.xhtml\"\/>    \r\n\t<\/ui:define>\r\n\t\r\n<\/ui:composition>\r\n<\/pre>\n<span id=\"Test\"><h3>Test<\/h3><\/span>\n<p>* Deploy to Tomcat<br \/>\n* Point browser to <a href=\"http:\/\/localhost:8080\/jsf2.myfaces2.trinidad2.one\/faces\/testcc\/testcc.xhtml\">http:\/\/localhost:8080\/jsf2.myfaces2.trinidad2.one\/faces\/testcc\/testcc.xhtml<\/a><\/p>\n<span id=\"_1\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/eclipse_jsf2.myfaces2.trinidad2.facelettaglib_test.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/eclipse_jsf2.myfaces2.trinidad2.facelettaglib_test.jpg\" alt=\"\" title=\"eclipse_jsf2.myfaces2.trinidad2.facelettaglib_test\" width=\"371\" height=\"268\" class=\"aligncenter size-full wp-image-4495\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/eclipse_jsf2.myfaces2.trinidad2.facelettaglib_test.jpg 371w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2012\/03\/eclipse_jsf2.myfaces2.trinidad2.facelettaglib_test-300x216.jpg 300w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><\/h6><\/span>\n<span id=\"Debug\"><h3>Debug<\/h3><\/span>\n<p>* Add to xhtml page:<\/p>\n<pre lang=\"xml\">\r\n<ui:debug hotkey=\"p\" rendered=\"true\"><\/ui:debug>\r\n<\/pre>\n<p>* Press control p to see debug info.<\/p>\n<span id=\"References\"><h3>References<\/h3><\/span>\n<p>* Apache MyFaces Trinidad 1.2 By: David Thomas<br \/>\n* <a href=\"http:\/\/www.jsftoolbox.com\/documentation\/facelets\/01-Introduction\/index.jsf\">Facelet Tools<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setup Test Project * Follow this post to setup a dynamic web project using MyFaces Trinidad in Eclipse. You can download the sample code to begin with. * Add CDI\/WELD support to the project. See this post for details. &#8211; &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=4476\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[120],"tags":[],"class_list":["post-4476","post","type-post","status-publish","format-standard","hentry","category-jsf"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-1ac","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4476"}],"version-history":[{"count":9,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4476\/revisions"}],"predecessor-version":[{"id":4756,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/4476\/revisions\/4756"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}