How to pass method expression to the Facelets tagfile

1k views Asked by At

I created a tagfile for a confirm dialog with a command button:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui" 
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:aym="http://aym.com/facelets"
    xmlns:rich="http://richfaces.org/rich"
>
    <h:body>
        <ui:composition>    
            <p:growl id="messages" />

            <h:panelGrid columns="1" cellpadding="5">   
                <p:commandButton value="#{label}" onclick="#{pupupId}.show()" type="button" ajax="false"/>
            </h:panelGrid>

            <p:confirmDialog message="#{message}"
                showEffect="bounce" hideEffect="explode"
                header="İşlem Onay" severity="alert" widgetVar="#{pupupId}">
                <p:commandButton value="Evet" update="messages" oncomplete="#{pupupId}.hide()" ajax="false"
                    action="#{actionMethod}" />
                <p:commandButton value="Hayır" onclick="#{pupupId}.hide()" type="button" /> 
            </p:confirmDialog>
        </ui:composition>
    </h:body>
</html>

Here's how I'm using it:

<aym:onayButon id="onay2" label="#{lbl.kaydet}" 
    actionMethod="#{userMB.addUser}" pupupId="onaylaPopup" 
    message="#{msg.onay_sonuc}"  />

I am passing the action method that I am going to call when I click the button. However, when I do that, then I am getting a PropertyNotFoundException:

WARNING: #{actionMethod}: javax.el.PropertyNotFoundException: /WEB-INF/tags/com/components/onayButton.xhtml @29,33 action="#{actionMethod}": /pages/index.xhtml @33,48 actionMethod="#{userMB.addUser}": Property 'addUser' not found on type com.otv.managed.bean.UserManagedBean
javax.faces.FacesException: #{actionMethod}: javax.el.PropertyNotFoundException: /WEB-INF/tags/com/components/onayButton.xhtml @29,33 action="#{actionMethod}": /pages/index.xhtml @33,48 actionMethod="#{userMB.addUser}": Property 'addUser' not found on type com.otv.managed.bean.UserManagedBean
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)

It works fine when I hardcode the action method in the tagfile like so:

<p:commandButton ... action="#{userMB.addUser}" />

How is this caused and how can I solve it?

1

There are 1 answers

1
L-Ray On BEST ANSWER

Try as a workaround to give action bean and action method as two separate parameters:

Template

<p:commandButton value="Evet" 
    update="messages" oncomplete="#{pupupId}.hide()" ajax="false"
    action="#{actionBean[actionMethod]}" />

call

<aym:onayButon id="onay2" label="#{lbl.kaydet}" 
    actionBean="#{userMB}" actionMethod="addUser" pupupId="onaylaPopup" 
    message="#{msg.onay_sonuc}"  />

On the call, the bean needs to be in curly brackets, the method name is only given as string. See also Solution on a similar topic .

Maybe it helps...