1

我有一个页面,其中表单包含一个 primefaces 咆哮,当添加消息时,更新效果很好,显示然后消失,就像我想要的那样。

我在我的一些页面中添加了模板,并在主布局文件中以单独的形式放置了咆哮,因此可以使用该模板从每个页面使用和更新它。但是,尽管我尝试添加消息并更新咆哮,但它从未出现过。虽然在响应中我看到更新是从服务器接收的,如下所示:

<partial-response><changes><update id="growlForm:growl">
<![CDATA[<span id="growlForm:growl"></span>
 <script id="growlForm:growl_s" type="text/javascript">
$(function(){PrimeFaces.cw('Growl','widget_growlForm_growl',
 {id:'growlForm:growl',sticky:true,life:6000,escape:true,msgs:
  [{summary:"Validation error!",detail:"Please check you input values.",severity:'error'}]});});
  </script>]]>
 </update>..... more changes

几乎唯一的问题是咆哮实际上并没有出现。它甚至可能与 jsf 模板没有任何关系,但我认为既然它在另一个页面上工作,它一定是它,因为我使用相同的方法和一切。

我使用的模板系统:

常见布局:

<h:head>
    <h:outputStylesheet name="style.css" library="css" />
    <script type="text/javascript" src="../resources/js/common.js"></script>
    <title><ui:insert name="title"></ui:insert></title>
</h:head>

<h:body>
    <h:form id="growlForm">
        <p:growl id="growl" showDetail="true" sticky="true" />
    </h:form>
    <div id="page">
        <div id="header">
            <ui:insert name="header">
                <ui:include src="/restricted/templates/commonHeader.xhtml" />
            </ui:insert>
        </div>

        <div id="content">
            <ui:insert name="content">
            </ui:insert>
        </div>

        <div id="footer">
            <ui:insert name="footer">
                <ui:include src="/restricted/templates/commonFooter.xhtml" />
            </ui:insert>
        </div>

    </div>

</h:body>

实际表单ui部分:

<ui:define name="content">
        <script>
            jQuery(document).ready(function() {
                update();
            });
        </script>
        <h:form id="invoiceForm" styleClass="defaultForm">
            <div class="defaultPanel">

                //.. irrelevant content

                <span class="block"> <p:commandButton id="submitButton"
                        actionListener="#{invoiceBean.submit}"
                        value="#{msg.button_label_submit}" update=":invoiceForm :growlForm:growl"
                        oncomplete="update()" />
                </span>
            </div>
        </h:form>
</ui:define>

谁能帮助我如何让咆哮出现?

编辑

有人要求发布“update()”函数的代码,但它实际上什么也没做,只是根据其他值更新一些输入值,它处于测试阶段,我试图重命名它,仍然不会显示咆哮。

function update() {
    // document.getElementById("total_price_amount").value = toFixed(ish *
    // 1.2,2);
    var sumNet = 0;
    var sumTax = 0;
    var sumTotal = 0;

    var selectvat = document.getElementById("invoiceForm:vat");
    var label = selectvat.options[selectvat.selectedIndex].text;
    var valueAsText = label.substring(0, label.length - 1);
    var valueAsInt = parseInt(valueAsText);

    var defaultTax = valueAsInt / 100;
    $("[id$='articleItemReference']")
            .each(
                    function() {
                        var currentId = $(this).attr('id');
                        var prefix = currentId.replace('articleItemReference',
                                '');
                        var quantity = document.getElementById(prefix
                                + 'quantity').value;
                        var price = document.getElementById(prefix + 'price').value;
                        // set price incl vat
                        var priceIncl = toFixed((1 + defaultTax) * price);
                        document.getElementById(prefix + 'priceInclVAT').value = priceIncl;
                        var discountAmount = document.getElementById(prefix
                                + 'discount').value;
                        var discountType = document.getElementById(prefix
                                + 'discountType').value;

                        var totalPrice = price * quantity;
                        var totalPriceWithDiscount;
                        if (discountType == 'percent') {
                            totalPriceWithDiscount = totalPrice
                                    * ((100 - discountAmount) / 100);
                        } else {
                            totalPriceWithDiscount = totalPrice
                                    - discountAmount;
                        }

                        document.getElementById(prefix + 'sum').value = toFixed(
                                totalPriceWithDiscount, 2);

                        var tax = totalPriceWithDiscount * defaultTax;

                        sumNet = sumNet + totalPriceWithDiscount;
                        sumTax = sumTax + tax;
                        sumTotal = sumTotal + (totalPriceWithDiscount + tax);
                    });
    document.getElementById("invoiceForm:sumOfAll").innerHTML = toFixed(
            sumTotal, 2);
    document.getElementById("invoiceForm:sumOfTax").innerHTML = toFixed(sumTax,
            2);
    document.getElementById("invoiceForm:sumOfNet").innerHTML = toFixed(sumNet,
            2);
}
4

0 回答 0