{"id":448,"date":"2007-12-08T12:40:07","date_gmt":"2007-12-08T18:40:07","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/archives\/000448"},"modified":"2007-12-08T12:40:07","modified_gmt":"2007-12-08T18:40:07","slug":"gwt-mini-pattern-use-a-span-to-enable","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/448","title":{"rendered":"GWT Mini Pattern: Use a span to enable"},"content":{"rendered":"<p>Since I last checked, <a href=\"http:\/\/www.mooreds.com\/wordpress\/archives\/000381\">you aren&#8217;t able to have more than one GWT module on a page<\/a>.\u00a0 However, each widget is independent, so it makes a lot of sense to package them up as separate modules.\u00a0 Then, you have one module that inherits from all of the other ones, and therefore all the widget code gets executed.\u00a0 Except, sometimes it makes sense for a widget to be on one page and not another.\u00a0 The easies way I have found to do this is to use a span tag with a unique id to mark a page for a component.\u00a0 Sometimes the span tag is where the component places itself&#8211;other times it just serves as a<br \/>\nmarker for a component which manipulates the DOM in other ways.<\/p>\n<p>The code often looks like this:<\/p>\n<p><code><\/p>\n<pre>\r\nRootPanel rp = RootPanel.get(SPAN_ID);\r\nif (rp != null) {\r\n\r\nMyComponent obj = new MyComponent();\r\nrp.add(obj);\r\n}<\/pre>\n<p><\/code><\/p>\n<p>Now, if we&#8217;re on a page that this component does not make sense on, it never gets intialized, no network calls are made, etc.<\/p>\n<p>One issue is that if you want to have the component in more than one place on the page, you need to handle that with special cases.\u00a0 You can simply use the same id twice, because it is bad form to have more than one element with the same id on a single page&#8211;ids are supposed to be globally unique on a page.\u00a0 If you could use a special tag, that&#8217;d be nice, but GWT does not support <code>getElementsByTagName<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since I last checked, you aren&#8217;t able to have more than one GWT module on a page.\u00a0 However, each widget is independent, so it makes a lot of sense to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,30],"tags":[],"class_list":["post-448","post","type-post","status-publish","format-standard","hentry","category-gwt","category-gwt-mini-patterns"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=448"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/448\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}