0

Facebook Like button

asked 2012-12-30 04:42:12 +0800

RichardL gravatar image RichardL
768 4

Hi all,
I'm trying to embed the Facebook Like button plugin (http://developers.facebook.com/docs/reference/plugins/like/). I want to do it in Java and I have tried using a ZK native component (where NDiv extends HtmlNativeComponent):

NDiv fbDiv = new NDiv();
		getWrapperDiv().appendChild(fbDiv);
		fbDiv.setDynamicProperty("class", "fb-like");
		fbDiv.setDynamicProperty("data-href", "http://www.google.com");
		fbDiv.setDynamicProperty("data-send", "true");
		fbDiv.setDynamicProperty("data-layout", "button_count");
		fbDiv.setDynamicProperty("data-width", "450");
		fbDiv.setDynamicProperty("data-show-faces", "false");
		fbDiv.setDynamicProperty("data-font", "arial");

I've also tried this just to see if it would work:
fbDiv.setPrologContent("<div class=\"fb-like\" data-font=\"arial\" data-show-faces=\"false\" data-width=\"450\" data-layout=\"button_count\" data-send=\"true\" data-href=\"http://www.google.com\"></div>");

The html works fine if I just put it in the JSP, but not when it's in the native comp.
Any ideas? Thanks,
Richard

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-12-30 07:20:43 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

updated 2012-12-30 07:23:05 +0800

Hi Richard,

You need to call the initialize script provided by facebook after the fbDiv is added to the page, e.g.,

<zk>
<!-- the fb root and initialization function,
      remove the exec fragment (document, 'script', 'facebook-jssdk')
      since we will call it manually -->
  <div id="fb-root"></div>
<script>(window.initializelike = function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
});</script>

  <div id="WrapperDiv">
  <button label="test">
    <attribute name="onClick"><![CDATA[
      // add the fbDiv
           ...
      // call the predefined initial function
      Clients.evalJavaScript("window.initializelike(document, 'script', 'facebook-jssdk')");
    ]]></attribute>
  </button>
  </div>

</zk>

Regards,
Ben

link publish delete flag offensive edit

answered 2012-12-30 10:35:53 +0800

RichardL gravatar image RichardL
768 4

Great! Thank you , Ben!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-12-30 04:42:12 +0800

Seen: 74 times

Last updated: Dec 30 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More