从ui:component内部更新primefaces growl

时间:2013-05-19 10:44:25

标签: java jsf primefaces

我有一个页面,其中表单包含一个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);
}

0 个答案:

没有答案