action and actionListener for p:commandButton in composite component
Asked Answered
C

1

5

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

Usage:

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

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>

And this is log:

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.

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.

Commendatory answered 14/10, 2013 at 16:36 Comment(3)
Is your wk:commandButton inside a form tag? Add the following code to the p:commandButton: ajax="#{empty cc.attrs.actionListener ? false : true}"Worser
I don't want use ajax in that case. Like the value in the button says. :)Commendatory
So put ajax = "false". The default value is true.Worser
I
7

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>
Intertidal answered 30/10, 2013 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.