我尝试根据辅助bean方法的结果呈现一个显示弹出面板的复合组件。到目前为止没有成功。希望得到一些帮助。
复合组件(conditionalActionLink.xhtml):
<ui:component
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="value"/>
<composite:attribute name="style"/>
<composite:attribute name="disabled"/>
<composite:attribute name="render"/>
<composite:attribute name="message" />
<composite:attribute name="renderedBtn" type="java.lang.Boolean"/>
<composite:attribute name="condition" required="true" method-signature="java.lang.Boolean action()"/>
<composite:attribute name="execAction" required="true" method-signature="void action()"/>
</composite:interface>
<composite:implementation>
<ui:debug hotkey="x" />
<h:form>
<a4j:commandLink id="actnlnx" value="#{cc.attrs.value}" oncomplete="#{managePurchases.billHasPaymentsApplied ? showMessage() : submitToServer() }" style="#{cc.attrs.style}" disabled="#{cc.attrs.disabled}"/>
<a4j:jsFunction name="showMessage" onbegin="#{rich:component('noticeDialog')}.show()" execute="@form"/>
<a4j:jsFunction name="submitToServer" action="#{cc.attrs.execAction}" render="#{cc.attrs.render}" execute="@form"/>
<rich:popupPanel id="noticeDialog" modal="true" autosized="true" resizeable="false" style="FONT-SIZE: large;">
<f:facet name="header" style="FONT-SIZE: large;">
<h:outputText value="Notice" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#" onclick="#{rich:component('noticeDialog')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<h:outputText value="#{cc.attrs.message}"/>
<br/><br/>
<h:commandButton value="Ok" onclick="#{rich:component('noticeDialog')}.hide(); return false;" style="FONT-SIZE: large;"/>
</rich:popupPanel>
</h:form>
</composite:implementation>
调用页面:
<cc:conditionalActionLink value="Delete" style="FONT-SIZE: large;text-decoration:none" message="This bill has payments applied. Please delete payments first." condition="#{managePurchases.billHasPaymentsApplied}" execAction="#{managePurchases.deleteBill}"/>
顺便说一句,我需要在复合组件中使用条件值,但是如何避免嵌套EL表达式的挑战:oncomplete="#{cc.attr.condition ? showMessage() : submitToServer() }"
支持Bean:
public Boolean getBillHasPaymentsApplied(){
applogger.entry();
//if(bill.getPayments().size() > 0)
return applogger.exit(true);
//else
//return applogger.exit(false);
}
public void deleteBill(){
applogger.entry();
applogger.debug("DELETE BILL HERE.");
//billDaoBean.deleteBill(bill);
applogger.exit();
}
我尝试了很多调整,在线搜索很多。对于此特定版本,错误消息是
javax.el.ELException:Function&#39; showMessage&#39;找不到
我正在寻找一种方法来实现这种行为。
提前感谢您的帮助!
答案 0 :(得分:1)
oncomplete
组件的<a4j:commandLink>
属性必须评估为String
。在这里,您的EL尝试根据未找到的布尔值调用showMessage()
或submitToServer()
java方法。
你想要的是一个带有JS函数名的String
,所以只需将函数名放在单引号之间,使它们成为String
:
oncomplete="#{managePurchases.billHasPaymentsApplied ? 'showMessage()' : 'submitToServer()'}"
我没有任何RichFaces准备好的游乐场(顺便说一句,从来没有使用过RichFaces),所以我无法测试,但它应该可以做到!