本文介绍了将EL方法表达式作为自定义Facelets标记文件的属性传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义JSF标记:

I created a custom JSF tag:

<ui:composition>
    <h:panelGroup>
        <rich:dataScroller id="#{id}" for="#{table}" execute="#{table}"
            page="#{scrollerPage}" render="#{table}-sc1" maxPages="5"
            fastControls="hide" oncomplete="#{onCompl}" scrollListener="#{scrollListenerBean[scrollListenerMethod]}" />
        <h:inputText value="#{scrollerPage}" id="#{table}-sc1" size="2">
            <f:convertNumber integerOnly="true" />
        </h:inputText>
        <h:outputText styleClass="outputText"
            value=" of #{scrollPagesCount}  " />
        <h:commandButton value="GO! " />
    </h:panelGroup>
</ui:composition>

要通过侦听器方法,我使用了很老的博客:

To pass the listener method, I used the solution suggested in a quite old blog:

<my:dataScroller id="idDS1" table="table1"
                    scrollerPage="#{bean.navigationHelper.scrollerPage}"
                    scrollPagesCount="#{bean.navigationHelper.scrollPagesCount}"
                    onCompl="initForm();"
                    scrollListenerBean="#{bean}"
                    scrollListenerMethod="aMethod" />

我的问题是:这是最好的方法吗?如何使该方法可选?

My questions are: is this the best way to do this? How can I make the method optional?

非常感谢您的帮助!再见!

Thanks a lot for any Help! bye!

推荐答案

如果您只能使用标准的JSF/EL工具并且不能创建自定义标记处理程序,那么这仍然是 only 的方式.

That's the only way anyway, provided that you can only use standard JSF/EL facilities and you cannot create a custom taghandler.

但是,您可以创建一个自定义标记处理程序,以将值表达式转换为方法表达式. OmniFaces JSF实用程序库为此专门提供了<o:methodParam>.另请参见 <o:methodParam>演示页面.

You could however create a custom taghandler to convert the value expression to a method expression. The OmniFaces JSF utility library has a <o:methodParam> for exactly this purpose. See also the <o:methodParam> demo page.

然后您可能会像这样:

<my:dataScroller ... scrollListener="#{bean.aMethod}" />

<o:methodParam name="scrollListenerMethod" value="#{scrollListener}" />
<rich:dataScroller ... scrollListener="#{scrollListenerMethod}" />

另请参见:

  • 动态ui包含和commandButton
  • See also:

    • Dynamic ui include and commandButton
    • 从理论上讲,您可以使用JSTL标记有条件地构建视图.像这样:

      Theoretically, you could use JSTL tags to build the view conditionally. Something like:

      <h:someComponent>
          <c:if test="#{not empty fooAttribute}">
              <f:attribute name="foo" value="#{fooAttriubte}" />
          </c:if>
      </h:someComponent>
      

      但是不幸的是,在特殊方法表达式侦听器属性的特殊情况下,这是不可能的.没有<rich:scrollListener>之类的东西,也没有允许您将RichFaces特定的scrollListener作为单独的标签绑定到<rich:dataScroller>的东西.不创建自定义标记处理程序所能做的最好的事情是将整个<rich:dataScroller>复制成两个<c:if>(或一个<c:choose>).一个带scrollListener,另一个不带scrollListener.这太笨拙了.您最好为此创建一个自定义的<my:richScrollListener>标记处理程序,然后将其放置在<c:if>中.

      But that's in the particular case of a special method expression listener attribute unfortunately not possible. There's no such thing as <rich:scrollListener> or something which allows you binding a RichFaces specific scrollListener as a separate tag to the <rich:dataScroller>. Best what you could do without creating custom taghandlers is duplicating the whole <rich:dataScroller> in two <c:if>s (or a <c:choose>); one with and other without scrollListener. This is too clumsy. You'd really better create a custom <my:richScrollListener> taghandler for this which you could then place in a <c:if>.

      这篇关于将EL方法表达式作为自定义Facelets标记文件的属性传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 05:57