复合组件中p:commandButton的action和actionListener

Woj*_*hKo 4 jsf primefaces composite-component

我正在制作复合组件,我有commandButton.但它不起作用.

用法:

<wk:commandButton value="Non-Ajax actionListener" actionListener="#{ioBean.saveListener}" />  
Run Code Online (Sandbox Code Playgroud)

组件代码:commandButton.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:cc="http://java.sun.com/jsf/composite">
<cc:interface>
    <cc:attribute name="value" />
    <cc:attribute name="action" method-signature="void action(javax.faces.event.ActionEvent)" default="null"/>
    <cc:attribute name="actionListener" method-signature="void actionListener(javax.faces.event.ActionEvent)" default="null"/>
    <cc:attribute name="styleClass" default="button" />
</cc:interface>
    <cc:implementation>
            <p:commandButton
                            value="#{cc.attrs.value}"
                            action="#{cc.attrs.action}"
                            actionListener="#{cc.attrs.actionListener}"
                            styleClass="#{styleClass}">
                <cc:insertChildren />
            </p:commandButton>
    </cc:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)

这是日志:

0000006c FaceletViewDe E   Inner component action not found when retargetMethodExpressions
0000006c FaceletViewDe E   Inner component actionListener not found when retargetMethodExpressions
0000006c srt           W com.ibm.ws.webcontainer.srt.SRTServletResponse setIntHeader SRVE8094W: Ostrze?enie: nie mo?na ustawi? nag?ówka. Odpowied? zosta?a ju? zatwierdzona.
Run Code Online (Sandbox Code Playgroud)

我认为问题在于action和actionListener的默认值.但是根据PrimeFaces文档,action和actionListener的默认值为null.一个选项是制作四个不同的变体,其中action和actionListener为null或已定义,但它似乎不是一个好的解决方案.

Bal*_*usC 6

使用<cc:attribute targets>而不是显式指定可能的null操作(侦听器).

<cc:interface>
    <cc:attribute name="value" />
    <cc:attribute name="action" targets="buttonId" />
    <cc:attribute name="actionListener" targets="buttonId" />
</cc:interface>
<cc:implementation>
    <p:commandButton id="buttonId" value="#{cc.attrs.value}" />
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)