尝试不同的方法来解决我提到的问题here,我创建了一个facelets标记库来使用一些格式化函数。
它适用于普通页面,但对于复合组件,该函数不会执行,也不会引发错误。
Taglib文件:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://www.spdata.com.br/jsf</namespace>
<composite-library-name>spd</composite-library-name>
<function>
<function-name>leftJustifyWithZeros</function-name>
<function-class>
br.com.spdata.util.Formatter
</function-class>
<function-signature>
String leftJustifyWithZeros(java.lang.String, java.lang.Integer)
</function-signature>
</function>
<function>
<function-name>replaceNewLineWithBrTag</function-name>
<function-class>
br.com.spdata.util.Formatter
</function-class>
<function-signature>
String replaceNewLineWithBrTag(java.lang.String)
</function-signature>
</function>
</facelet-taglib>
复合组件:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:spd="http://www.spdata.com.br/jsf"
>
<cc:interface>
<cc:attribute name="value" required="true" />
</cc:interface>
<cc:implementation>
<h:outputText
id="#{cc.attrs.id == null ? 'visualizar' : cc.attrs.id}"
value="Visualizar"
rendered="#{cc.attrs.value != null and not empty cc.attrs.value}"
/>
<p:tooltip
value="#{spd:replaceNewLineWithBrTag(cc.attrs.value)}"
for="#{cc.attrs.id == null ? 'visualizar' : cc.attrs.id}"
/>
</cc:implementation>
</html>
我错过了什么?
谢谢, 菲利普