【发布时间】: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,但不确定它是否符合您的要求。