Facebook社交插件和JSF [英] Facebook social plugins and JSF

查看:125
本文介绍了Facebook社交插件和JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将Facebook社交插件整合到JSF应用程序中。这建议我将fbml命名空间添加到在回复中呈现的xhtml文件中。

I have to integrate the Facebook social plugins into a JSF application. This recommends that I add the fbml namespace to the xhtml file that it's rendered in the response.

我在我的XHTML文件中:

I have in my XHTML file:

<!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:ui="http://java.sun.com/jsf/facelets"
  ...
  xmlns:fb="http://www.facebook.com/2008/fbml"
  xmlns:og="http://ogp.me/ns#">

但是, fb og 命名空间将不会在渲染的源中显示,只能显示XHTML命名空间。如何将这些命名空间写入响应?

But the fb and og namespace won't be shown in the rendered source, only the XHTML namespace. How can I get these namespaces written to the response?

有这个问题: https://stackoverflow.com/questions/5199176/include-facebook-social-plugins-in-a-jsf2-page ,但它没有已经回答了。

There is this issue: https://stackoverflow.com/questions/5199176/include-facebook-social-plugins-in-a-jsf2-page but it has not been answered yet.

我唯一的想法是制作一个iframe,并包含一个简单的XHTML文件(不是一个Facelet,只是纯XHTML),但这似乎要肮脏。

The only idea I've got is to make an iframe and include a simple XHTML file (not a Facelet, just pure XHTML), but this seems to be dirty.

我希望有人有更好的解决方案。

I hope someone has a better solution to that.

其他信息:我正在使用facelets和seam 2.2。

Additional information: I'm using facelets and seam 2.2.

我假设 ResponseWriter.startDocument()打印Doctype和< html> 元素,是否正确?或者它只是另一个 UIComponent ,呈现< html> 元素?如果我可以实现一个自定义的 ResponseWriter 并覆盖 startDocument()并将我的自定义作者设置为默认值

I assume that ResponseWriter.startDocument() prints the Doctype and <html> element, is that correct? Or ist it just another UIComponent that renders the <html> element? It would be nice if I just could implement a custom ResponseWriter and override startDocument() and set my custom writer as default.

这导致我有两个问题:


  1. 我应该覆盖哪个类所以我不必实现抽象的每个方法 ResponseWriter

  2. 我如何告诉我的应用程序使用我的自定义 ResponseWriter

  1. Which class should I override so I don't have to implement every method of the abstract ResponseWriter?
  2. How would I tell my application to use my custom ResponseWriter?

或者实现一个自定义组件,呈现< html> 标记工作?我在问这个问题,因为看起来似乎是出现< html> 标签,似乎没有办法改变这个,所以我想到了覆盖 ResponseWriter

Or does implementing a custom component that renders the <html> tag the job? I'm asking this because facelets seems to render the <html> Tag by itself and there seems to be no way to change this, that's why I came up with overriding the ResponseWriter.

推荐答案

我发现我只需要写一个自定义组件:

I found out that I just had to write a custom component:

public class CvHTML extends UIOutput {
    @Override
    public void encodeBegin(final FacesContext context) throws IOException {
        final ResponseWriter writer = context.getResponseWriter();
        writer.startDocument();
        writer.startElement("HTML", null);
        writer.writeAttribute("xmlns", "http://www.w3.org/1999/xhtml", null);
        writer.writeAttribute("xmlns:fb", "http://www.facebook.com/2008/fbml", null);
        writer.writeAttribute("xmlns:og", "http://ogp.me/ns#", null);
    }

    @Override
    public void encodeEnd(final FacesContext context) throws IOException {
        final ResponseWriter writer = context.getResponseWriter();
        writer.endElement("HTML");
        writer.endDocument();
    }
}

现在在主模板中调用:

<cv:html xmlns="http://www.w3.org/1999/xhtml" lang="en"
    xmlns:s="http://jboss.com/products/seam/taglib"
    ....
    xmlns:cv="http://your.name.space/foo">

这篇关于Facebook社交插件和JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆