我正在使用Javascript为FB登录网站开发一个应用程序。我在html中试过了,效果很好。当我转换成JSF时,它会给出一个错误。
这是我的fbLogin.xhtml
代码。
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:fb="http://www.facebook.com/2008/fbml">
<h:head>
<title>FB Login</title>
<link rel="stylesheet" type="text/css" href="./xmlhttp/css/rime/rime.css"/>
</h:head>
<h:body styleClass="ice-skin-rime">
<fb:login-button scope="email"></fb:login-button>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<APP_ID>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
showMe = function(response) {
if (response.status !== 'connected') {
div.innerHTML = '<em>Not Connected</em>';
} else {
FB.api('/me', function(response) {
var i=0;
for (var key in response) {
i++;
switch(i){
case 1: document.getElementById("formId:id").value=response[key]; break;
case 2: document.getElementById("formId:name").value=response[key]; break;
case 5: document.getElementById("formId:link").value=response[key]; break;
case 6: document.getElementById("formId:userName").value=response[key]; break;
case 19: document.getElementById("formId:email").value=response[key]; break;
}
}
});
}
};
FB.getLoginStatus(function(response) {
showMe(response);
FB.Event.subscribe('auth.authResponseChange', showMe);
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<h:form id="formId">
<table>
<tr><td><a>ID : <h:inputText id="id" value="#{fbLogin.id}" /> </a></td></tr>
<tr><td><a>Name : <h:inputText id="name" value="#{fbLogin.name}" /> </a></td></tr>
<tr><td><a>Link : <h:inputText id="link" value="#{fbLogin.link}" /> </a></td></tr>
<tr><td><a>User Name : <h:inputText id="userName" value="#{fbLogin.userName}" /> </a></td></tr>
<tr><td><a>E-Mail : <h:inputText id="email" value="#{fbLogin.email}" /> </a></td></tr>
<tr><td><h:commandButton value="Register" action="#{fbLogin.Display}" /></td></tr>
</table>
</h:form>
</h:body>
</html>
使用JSF编写代码的原因是,我需要将用户信息获取到我的backBean中,以便存储到数据库中。
当我尝试运行这个应用程序时,我在浏览器中收到警告:
Warning: This page calls for XML namespace http://www.facebook.com/2008/fbml declared with prefix fb but no taglibrary exists for that namespace.
我的代码中有什么错误?
当您在webapp的web.xml
中将javax.faces.PROJECT_STAGE
设置为Development
,并且Facelets遇到无法解析为JSF兼容标记库的XML命名空间时,您将得到此消息。显示此警告只是为了通知(启动)开发人员XML命名空间中可能出现的意外拼写错误或标记库配置中的错误。
然而,在这种特殊情况下,有问题的XML名称空间实际上引用了外部的FacebookJavaScriptneneneba API,而不是PrimeFaces、OmniFaces等JSF标记库。
您可以忽略此警告。当您将JSF项目阶段设置回Production
,或者删除整个上下文参数(它已经默认为Production
)时,不会出现此警告。