【发布时间】:2014-02-05 10:12:17
【问题描述】:
我想要做的是将一个通用的数据表头声明为一个复合组件。但是这个答案让我直截了当,因为它没有被渲染:
How to create a composite component for a datatable column?
基本上,它指示我尝试我自己的 taglib,而且效果非常好,只是我的标题中有一个重新渲染的链接。按下此链接时会抛出 MethodNotFoundException。
这是我的自定义标签库:
<?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://stackoverflowdummy.com/dumb/components</namespace>
<tag>
<tag-name>tableHeader</tag-name>
<source>tags/tableHeader.xhtml</source>
<attribute>
<description></description>
<name>value</name>
</attribute>
<attribute>
<description>The listener that handles sorting</description>
<name>sortAction</name>
<method-signature>java.lang.String action()</method-signature>
</attribute>
<attribute>
<description>The property that holds the current id to sort on
</description>
<name>sortValue</name>
</attribute>
<attribute>
<description>The component that needs to be updated after changes
</description>
<name>reRender</name>
</attribute>
</tag>
</facelet-taglib>
我尝试不使用方法签名,也尝试删除“动作”。我的 web.xml 确实包含这样的 taglib:
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/cc.taglib.xml</param-value>
</context-param>
我也尝试过使用“facelets.LIBRARIES”,但没有任何区别。
<h:commandLink value="#{o.label}" action="#{sortAction}" immediate="true" reRender="#{reRender}">
<f:setPropertyActionListener target="#{sortValue}" value="#{o.column.sortId}" />
</h:commandLink>
最终用途定义如下:
sortAction="#{myBean.sort}"
该 bean 有一个使用签名 String sort(); 调用的方法;如果我只是定义它并跳过使用我自己的标签,它会非常有效。然而,除了 action 方法之外,一切都适用于标签...
【问题讨论】:
-
不知道为什么有人添加了一个没有关注者的标签和另一个更多关于 JSF 1.2 facelets 库的标签,但无论如何;)
标签: jsf-2 primefaces facelets myfaces methodexpression