带有条件弹出面板的 JSF 复合组件

JSF Composite Component with conditional popup panel

我正在尝试呈现一个复合组件,该组件根据支持 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 'showMessage' not found

我正在寻找实现此行为的方法。

提前感谢您的帮助!

<a4j:commandLink> 组件的 oncomplete 属性的计算结果必须为 String。在这里,您的 EL 尝试根据未找到的布尔值调用 showMessage()submitToServer() java 方法。

你想要的是带有JS函数名的String,所以只需将函数名放在单引号之间,使它们成为String:

oncomplete="#{managePurchases.billHasPaymentsApplied ? 'showMessage()' : 'submitToServer()'}"

我没有任何 RichFaces 就绪的游乐场(顺便说一句,我也从未使用过 RichFaces),所以我无法测试,但它应该可以解决问题![​​=18=]