我正在尝试渲染具有属性的head
元素。prefix
为了在 JSF 中做到这一点:
<h:head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# XXXX: http://ogp.me/ns/fb/XXXX#">
我创建了一个自定义head
渲染器:
public class FacebookHeadRenderer extends HeadRenderer{
@Override
public void encodeBegin(FacesContext context, UIComponent component)
throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("head", component);
RenderKitUtils.renderPassThruAttributes(context,
writer,
component,
HEAD_ATTRIBUTES);
System.out.println("FacebookHeadRenderer!");
}
private static final Attribute[] HEAD_ATTRIBUTES;
static {
Attribute[] baseAttributes = AttributeManager.getAttributes(
AttributeManager.Key.OUTPUTHEAD);
HEAD_ATTRIBUTES = new Attribute[baseAttributes.length + 1];
for (int i = 0; i < baseAttributes.length; ++i) {
HEAD_ATTRIBUTES[i] = baseAttributes[i];
}
HEAD_ATTRIBUTES[HEAD_ATTRIBUTES.length - 1] = Attribute.attr("prefix");
}
}
并将其注册在faces-config.xml
:
<render-kit>
<renderer>
<component-family>javax.faces.Output</component-family>
<renderer-type>javax.faces.Head</renderer-type>
<renderer-class>com.localgp.jsf.FacebookHeadRenderer</renderer-class>
</renderer>
</render-kit>
FacebookRenderer
正在调用(通过FacebookHeadRenderer!
打印验证),prefix
但未呈现该属性。
作为健全性检查,我添加了lang
属性:
<h:head lang="en_AU"
prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# XXXX: http://ogp.me/ns/fb/XXXX#">
我得到的只是
<head lang="en_AU">
想法?