2014-01-16 47 views
1

我想要做的是声明一个通用的数据表头作为一个复合组件。但这个答案让我直,因为它并没有呈现:自定义taglib结果MethodNotFoundException

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}" 

即豆有一个称为与签名字符串方法排序();如果我只是定义它并跳过使用我自己的标签,它的工作非常好。但是,除了动作方法外,所有内容都可以与标签一起工作...

+1

http://showcase.omnifaces.org/taghandlers/methodParam – BalusC

+0

DONO为什么有人未添加追随者标签,另一个更多的是JSF 1.2 Facelets的库,但无论;) –

回答

2

JavaBean规范提供了有关如何调用方法的多种方法。其实你可以用正常的方式拨打电话#{actionBean.actionMethod},也可以拨打#{actionBean['actionMethod']}

您给出的排序操作是作为MethodExpression传送的,与ValueExpression相比,在某些JSF环境中给我带来了问题。

我想什么你尝试testwise是,给行动作为两个独立的(值)参数:

  • sortActionBean="#{myBean}"
  • sortActionMethod="sort"

,并呼吁那些模板如#{sortActionBean['sortActionMethod']}。关于此主题的好文章是Passing action methods facelets tags

希望它可以帮助...

+0

我会尝试一下,thx –

+1

它按预期工作,谢谢。其实我并不介意强制排序方法的名称,所以我只是将bean绑定到我的自定义组件,并从那里#{bean.sort}。有用。 –