【问题标题】:JSF Composite Component with conditional popup panel带有条件弹出面板的 JSF 复合组件
【发布时间】:2015-08-29 13:22:22
【问题描述】:

我正在尝试渲染一个复合组件,该组件根据支持 bean 方法的结果显示一个弹出面板。至今没有成功。不胜感激。

  • GlassFish 4.1
  • Mojarra 2.2
  • RichFaces 4.5.4

复合组件(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.E​​LException:找不到函数“showMessage”

我正在寻找一种方法来实现这种行为。

提前感谢您的帮助!

【问题讨论】:

    标签: jsf richfaces el composite-component


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 非常感谢!这解决了问题的那一部分。现在我需要能够访问支持 bean 属性,而不是通过硬编码属性(“managePurchases.billHasPaymentsApplied”),而是通过传入要评估的属性作为复合组件的属性。请注意,三元运算符需要一个布尔值,而不是 bean 方法。我无法在 cc 之外评估它并传入布尔值,因为我使用 f:setPropertyActionListener(此处代码中未显示)来设置作为评估一部分的支持 bean 属性。
    • 您能否在问题中添加f:setPropertyActionListener 部分以进行澄清?
    • 再次感谢。我已经解决了我遇到的最后一个问题。不得不处理这个表单问题link
    • 很高兴它现在可以工作了!关于您在编辑建议中的问题(它工作正常,只是当复合组件位于其中 4 个的数据表中时它调用 #{customerAccounts.billHasPaymentsApplied} 4 次??),这是预期的行为. Getter 在 JSF 中被多次调用,所以不要在其中执行任何昂贵的逻辑!见this
    猜你喜欢
    • 2012-11-11
    • 2011-07-23
    • 2015-11-22
    • 2011-10-10
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    相关资源
    最近更新 更多