我使用命令按钮为确认对话框创建了一个标记文件:
<?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>
以下是我使用它的方式:
<aym:onayButon id="onay2" label="#{lbl.kaydet}"
actionMethod="#{userMB.addUser}" pupupId="onaylaPopup"
message="#{msg.onay_sonuc}" />
当我点击按钮时,我正在传递我要调用的动作方法。但是,当我这样做时,我得到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)
当我在tagfile中对action方法进行硬编码时,它可以正常工作:
<p:commandButton ... action="#{userMB.addUser}" />
这是如何引起的?如何解决?
答案 0 :(得分:1)
尝试将action bean和action方法作为两个单独的参数进行解决:
模板
<p:commandButton value="Evet"
update="messages" oncomplete="#{pupupId}.hide()" ajax="false"
action="#{actionBean[actionMethod]}" />
呼叫
<aym:onayButon id="onay2" label="#{lbl.kaydet}"
actionBean="#{userMB}" actionMethod="addUser" pupupId="onaylaPopup"
message="#{msg.onay_sonuc}" />
在调用中,bean需要使用大括号,方法名称仅以字符串形式给出。另请参阅Solution on a similar topic。
也许有帮助...