jQueryモバイルフレームワークでJSF2.1を使用するには、HTML5属性<h:commandLink/>
をサポートするタグのカスタムレンダラーを作成する必要がありました。data-*
私のJSFマークアップとこのマークアップによって生成される出力は次のとおりです。
<h:commandLink value="Prev" data-theme="e" data-role="button" data-inline="true" data-mini="true" data-icon="arrow-l"/>
<h:commandLink value="Page 1 of 3" data-theme="e" data-role="button" data-inline="true" data-mini="true"/>
<h:commandLink value="Next" data-theme="e" data-role="button" data-inline="true" data-mini="true" data-icon="arrow-r" data-iconpos="right"/>
私のカスタムレンダラーが2番目と3番目のタグを適切にレンダリングすることは明らかですが<h:commandLink/>
、1番目のタグはレンダリングしません。最初のdata-*
タグに属する属性は、直接の親<div/>
タグでレンダリングされるようです。これは、Mojarra(私が使用している)の奇妙な(そしてバグのある)動作のようV 2.1.11
です。これを克服する方法を教えてください。
私のカスタムレンダラーコードは次のとおりです。
public class MyCommandLinkRenderer extends CommandLinkRenderer {
@Override
public void encodeBegin(FacesContext context, UIComponent component) {
String[] attributes = {"data-theme", "data-role", "data-icon", "data-inline", "data-mini", "data-iconpos"};
ResponseWriter writer = context.getResponseWriter();
try {
for (String attribute : attributes) {
String value = (String) component.getAttributes().get(attribute);
if (value != null) {
writer.writeAttribute(attribute, value, attribute);
System.out.println(attribute + " " + value);
}
}
super.encodeBegin(context, component);
} catch (Exception e) {
}
}
}