我试着写一个jsf标签libary。因此,我创建了一个libary,它提供了一个facelet: AbButton.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:b="http://bootsfaces.net/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<c:choose>
[... other button variants...]
<c:when test="#{type == 'command' and not empty look}">
<b:commandButton value="#{value}" action="#{bean[action]}" id="#{id}" actionListener="#{bean[actionListener]}"
update="#{update}" look="#{look}" size="#{size}" iconAwesome="#{icon}" style="#{style}"/>
</c:when>
</c:choose>
</ui:composition>我创建了一个描述属性的taglib.xml。
<tag>
<tag-name>abButton</tag-name>
<description><![CDATA[Flexible Button Implementierung. Von Bootsfaces Button abgeleitet.]]></description>
<source>resources/tags/AbButton.xhtml</source>
[...]
<attribute>
<description><![CDATA[ stuff]]></description>
<name>action</name>
<required>false</required>
<type>javax.el.MethodExpression</type>
</attribute>
<attribute>
<description><![CDATA[stuff]]></description>
<name>actionListener</name>
<required>false</required>
<type>javax.el.MethodExpression</type>
</attribute>
[...]
</tag>最后,但并非最不重要的是,我在一个测试应用程序中实现了它。Button.xhtml
<h:body>
<h:form>
<a:abButton type="command" id="command" bean="#{button}" action="action" actionListener="actionListener" value="Command Button" style="margin-right:20px;" look="primary"/>
</h:form>
</h:body>和一个名为Button.java的支持豆
@Named("button")
@RequestScoped
public class Button {
public void action(){
System.out.println("action");
}
public void actionListener(){
System.out.println("action listener");
}
}如果我现在使用这个按钮,动作和actionListener方法都会被执行两次。如果删除actionListener,则操作方法只执行一次。同样的事情正在发生,我使用不同的bean,让我们说
AbButton.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:b="http://bootsfaces.net/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<c:choose>
[... other button variants...]
<c:when test="#{type == 'command' and not empty look}">
<b:commandButton value="#{value}" action="#{bean2[action]}" id="#{id}" actionListener="#{bean[actionListener]}"
update="#{update}" look="#{look}" size="#{size}" iconAwesome="#{icon}" style="#{style}"/>
</c:when>
</c:choose>
</ui:composition>和Button.xhtml
<h:body>
<h:form>
<a:abButton type="command" id="command" bean="#{button}" bean2="#{button}" action="action" actionListener="actionListener" value="Command Button" style="margin-right:20px;" look="primary"/>
</h:form>
</h:body>如果我使用Omnifaces :methodParam这样做,也会发生同样的情况:
AbButton.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:b="http://bootsfaces.net/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<c:choose>
[... other button variants...]
<c:when test="#{type == 'command' and not empty look}">
<o:methodParam name="actionMethod" value="#{action}"/>
<o:methodParam name="actionListenerMethod" value="#{actionListener}"/>
<b:commandButton value="#{value}" action="#{actionMethod}" actionListener="#{actionListenerMethod}" id="#{id}" look="#{look}"
update="#{update}" size="#{size}" iconAwesome="#{icon}" style="#{style}"/>
</c:when>
</c:choose>
</ui:composition>和button.xhtml
<h:body>
<h:form>
<a:abButton type="command" id="command" action="#{button.action}" actionListener="#{button.actionListener}" value="Command Button" style="margin-right:20px;" look="primary"/>
</h:form>
</h:body>情况也是如此。使用action和actionListener active,将执行两次。如果删除actionListener,则操作方法只执行一次。我希望这是一个更好的理解。有什么帮助吗?
发布于 2016-05-19 09:12:26
啊,现在我明白了。这是与第295期相关的bootsfaces 0.8.1中的一个bug。通过对Bootsfaces 0.8.5的更新,一切都如预期的那样工作。也许这能帮助那些面临同样问题的人。
https://stackoverflow.com/questions/37303567
复制相似问题