Facebook social plugins and JSF
Asked Answered
M

1

0

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 dirty.

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.

Midmost answered 23/8, 2011 at 13:48 Comment(0)
M
1

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">
Midmost answered 26/8, 2011 at 13:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.