【问题标题】:Passing Parameters in action listener event in a custom tag在自定义标记中的动作侦听器事件中传递参数
【发布时间】:2019-11-20 08:11:29
【问题描述】:

在继续构建自定义标签的过程中,除了将参数传递给 beans 方法之外,所有过程都已完成并且正在正常工作。我试过了,但无法传递参数,下面是代码。

web.xml

    <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/pinnacleTags.taglib.xml</param-value>
    </context-param>

标签

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib>
    <namespace>pinnacleTags/facelets</namespace>
    <tag>
        <tag-name>PinnacleCombo</tag-name>
        <source>buttonPanel.xhtml</source>
        <attribute>
            <name>textBoxValue</name>
        </attribute>
        <attribute>
            <name>caption</name>
        </attribute>
        <attribute>
            <name>btnCaption</name>
        </attribute>
        <attribute>
            <name>textBoxWidth</name>
        </attribute>
        <attribute>
            <name>btnHeight</name>
        </attribute>
        <attribute>
            <name>btnWidth</name>
        </attribute>
        <attribute>
            <name>actionListenerBean</name>
        </attribute>
        <attribute>
            <name>actionListenerBean</name>
            <method-signature>void actionListener(javax.faces.event.ActionEvent)</method-signature>
        </attribute>
        <attribute>
            <name>actionListenerMethod</name>
            <method-signature>method-signature="java.lang.String action(javax.faces.event.ActionEvent)"</method-signature>
        </attribute>
    </tag>
</facelet-taglib>

组件

        <ui:composition> 
            <div>
                <h:outputLabel value="#{caption}" />
                <p:inputText value="#{textBoxValue}" style="width: #{textBoxWidth}; " />
                <p:commandButton type = "submit" 
                                 value = "#{btnCaption}" 
                                 actionListener="#{actionListenerBean[actionListenerMethod]}"
                                 style="height: #{btnHeight}; width: #{btnWidth};" />
            </div>
        </ui:composition>

最后是用途

            <pt:PinnacleCombo id="clientID" 
                                textBoxValue="#{customTags.clientID}"
                                caption="Client ID: " 
                                textBoxWidth="150px" 
                                btnHeight="35px" 
                                btnCaption="Press"
                                actionListenerBean="#{customTags}"
                                actionListenerMethod="btnPressed"/>

我不知道如何将参数传递给menthod,请建议。

【问题讨论】:

  • 顺便说一句,这不是复合组件,而是自定义标签。
  • 感谢更正,您可以建议如何将参数传递给方法吗???
  • 尝试删除method-signatures。 bean 应该是一个对象,方法只是方法的名称。
  • @jasper-de-vries 我试过删除你提到的但没有成功。
  • 您检查过showcase.omnifaces.org/taghandlers/methodParam 吗?它允许传递带有参数的methidExpressions,但不确定它是否符合您的要求。

标签: jsf el


【解决方案1】:

最后正如@Selaron 建议的那样,自定义标签在使用omnifaces 之后是

        <ui:composition> 
            <h:outputLabel value="#{caption}" />
            <p:inputText value="#{textBoxValue}" style="width: #{textBoxWidth}; " />
            <o:methodParam name="method" value="#{actionListenerBeanMethod}" />
            <p:commandButton type = "submit" 
                             value = "#{btnCaption}" 
                             actionListener="#{method}"
                             style="height: #{btnHeight}; width: #{btnWidth};" />
        </ui:composition>

函数调用很简单

actionListenerBeanMethod="#{customTags.btnPressed('Value Passed')}"

感谢@Selaron 的帮助。

【讨论】:

    猜你喜欢
    • 2010-12-24
    • 2014-10-15
    • 2019-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 2012-06-01
    • 1970-01-01
    相关资源
    最近更新 更多