在继续构建自定义标签时,除了将参数传递给bean方法之外,所有过程都已经完成并且工作正常。我尝试过但无法传递参数,以下是代码。
web.xml
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/pinnacleTags.taglib.xml</param-value>
</context-param>
tabib
<?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"/>
我不知道如何将参数传递给方法,请建议。
最后就像@Selaron所建议的那样,自定义标签在使用了全能面之后是
<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寻求帮助。