开发者

Facebook social plugins and JSF

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.

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#">

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?

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

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 di开发者_JAVA百科rty.

I hope someone has a better solution to that.


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

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.

This leads me to 2 questions:

  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?

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();
    }
}

and call now in the main template:

<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">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜