2011-11-26 39 views
1

我想「喜歡」按鈕,Facebook的整合到我的網頁,所以這裏是結果:如何將Facebook插件與JSF 2頁面集成?

<!DOCTYPE html> 
<html lang="pt-br" 
     xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:ui="http://java.sun.com/jsf/facelets" 
     xmlns:h="http://java.sun.com/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:fn="http://java.sun.com/jsp/jstl/functions" 
     xmlns:rich="http://richfaces.org/rich" 
     xmlns:a4j="http://richfaces.org/a4j" 
     xmlns:fb="http://ogp.me/ns/fb#"> 


<h:head> 
</h:head> 

<h:body> 
    <div id="fb-root"></div> 
    <script> 
     window.fbAsyncInit = function() { 
     FB.init({ 
      appId  : '<filled with my app id>', // App ID 
      channelURL : '//www.suaparte.org', // Channel File 
      status  : true, // check login status 
      cookie  : true, // enable cookies to allow the server to access the session 
      oauth  : true, // enable OAuth 2.0 
      xfbml  : true // parse XFBML 
     }); 

     // Additional initialization code here 
     }; 

     // Load the SDK Asynchronously 
     (function(d){ 
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     d.getElementsByTagName('head')[0].appendChild(js); 
     }(document)); 
    </script> 

    <div id="header"> 
     <ui:insert name="header"> 
      Header area. Please insert the header! 
     </ui:insert>  
    </div> 


    <div id="content"> 
     <ui:insert name="content"> 
      Content area. Please insert the content! 
     </ui:insert> 
    </div> 

    <div id="footer"> 
     <fb:like href="suaparte.org" send="true" width="450" show_faces="true"></fb:like>  
    </div> 

</h:body> 

</html> 

「喜歡」的按鈕出現,但下方出現如下信息:

Warning: This page calls for XML namespace http://ogp.me/ns/fb# declared with prefix fb but no taglibrary exists for that namespace. 

回答

2

忽略警告。它來自Facelets,它是一種基於XML的視圖技術,並期望所有的XML名稱空間都能引用Facelets標籤庫。如果您試圖引用一個根本不存在於類路徑中的Facelets標記庫,則此警告在開發過程中應該是有用的。例如,當您嘗試使用RichFaces組件但忘記實際安裝RichFaces時。

在Facebook的情況下,XML名稱空間實際上是由JavaScript在客戶端解釋並且工作正常,因此您可以放心地忽略該警告。如果您將javax.faces.PROJECT_STAGE設置爲Production,它將不會出現。這些警告僅在設置爲Development時纔會顯示。

+0

好的,謝謝你的解釋朋友。 =] –

+0

不客氣。 – BalusC