复合组件中p:commandButton的action和actionListener [英] action and actionListener for p:commandButton in composite component

查看:91
本文介绍了复合组件中p:commandButton的action和actionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作具有CommandButton的复合组件.但这是行不通的.

I am making composite component where i have commandButton. But it doesn't work.

用法:

<wk:commandButton value="Non-Ajax actionListener" actionListener="#{ioBean.saveListener}" />  

组件代码:commandButton.xhtml

Code of component: 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>

这是日志:

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.

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

I think the problem is with default value for action and actionListener. But according to the PrimeFaces documentation, default value for action and actionListener is null. One option is to make four different variants where action and actionListener are null or are defined but it doedn't seem to be good solution.

推荐答案

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

Use <cc:attribute targets> instead of explicitly specifying a possibly null action(listener).

<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>

这篇关于复合组件中p:commandButton的action和actionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆