将参数传递给p:remoteCommand到支持bean方法并在页面提交之前获取结果

时间:2015-10-26 06:29:46

标签: jquery jsf primefaces jsf-2.2

在我的要求中,我有4个文本提交数量,费率,税率,总金额     值输入数量,税率后计算它应显示在总计中它工作正常但现在这个Grand Total我需要传递给托管bean方法并且在提交之前它应该显示结果在Grand Total提交

reference page image 这是我的xhtml页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"> 


<h:head>
    <title>ACIM</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="../css/global.css" />

    <h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
    <h:outputScript target="head"> 
 $ = jQuery;
        $(document).ready(function(){
    $("input").keyup(function(){
          var val1 = +$("#myForm\\:quantit").val();
          var val2 = +$("#myForm\\:rte").val();
          $("#myForm\\:total_Amount").val(val1*val2);
         var val3 = +$("#myForm\\:total_Amount").val();           
          var val4 = $("#myForm\\:tax").val();
           $("#myForm\\:grand_Total").val(val3*val4/100);
           command([{name:'param',value:val3}]);           
     }); 
});
</h:outputScript>
</h:head>
<h:body>

    <h:form>
        <div id="header">
            <h:panelGrid columns="2">
                <h1 id="logo">
                    <img src="../images/worldofficelogo-white.png" alt="image"
                        class="logo" />
                </h1>
                <h2 class="slogan">                 
                </h2>
            </h:panelGrid>          
        </div>
        <div id="tabs">
            <div id="tabs">
                <ul class="box">

                    <li><a href="accountsHome.xhtml">Expense</a></li>
                    <li id="active"><a href="accountspurchaseorder.xhtml">Purchase
                            Order</a></li>
                    <li><a href="accountspurchaseentry.xhtml">Purchase Entry</a></li>
                    <li><a href="#">Invoice</a>
                        <ul>
                            <li><a href="SalesInvoice.xhtml">Sales Invoice</a></li>
                            <li><a href="ServiceInvoice.xhtml">Service Invoice</a></li>
                        </ul></li>

                </ul>
            </div>
        </div>
    </h:form>
    <h:form id="myForm">
        <div class="msg">
            <h:panelGrid columns="2" width="100%">
                <h2>Welcome to Your P.O Management</h2>
            </h:panelGrid>
        </div><br/><br/>
        <hr style="margin-top: 24px;" />
        <div id="page" class="box">
            <p:messages for="login" showDetail="true" closable="true"
                style="text-align:center"></p:messages>
            <div class="content" style="margin-left: 200px">
                <h:panelGrid columns="6" cellpadding="5" cellspacing="5">                   

                    <h:outputText value="Quantity"></h:outputText>
                    <h:inputText class="input" id="quantit"
                        value="#{purchaseOrderBean.quantity}">                      
                    </h:inputText>                  


                    <h:outputText value="Rate In"></h:outputText>
                    <h:inputText class="input" id="rte"
                        value="#{purchaseOrderBean.rate}" required="true">                      
                    </h:inputText>

                    <h:outputText value="Tax Rate" class="left1"></h:outputText>
                    <h:inputText class="input" id="tax" value="#{purchaseOrderBean.taxRate}" required="true">                       
                    </h:inputText>                  

                </h:panelGrid>
                <br /><br />
                <h:outputText value="Total Amount" class="total"></h:outputText>
                <h:inputText class="input" style="border:none;margin-left:25px"
                    readonly="true" id="total_Amount"
                    value="#{purchaseOrderBean.totalAmount}">
                </h:inputText>
                <br /> <br /> <br />

                <h:outputText value="Grand Total" class="total"></h:outputText>
                <h:inputText class="input" style="border:none;margin-left:25px"
                    readonly="true" id="grand_Total"
                    value="#{purchaseOrderBean.grandTotal}">
                    <f:convertNumber type="currency" currencySymbol="rs"
                        currencyCode="INR" locale="en" />
                </h:inputText>
                <br /> <br /> <br />

                <h:outputText value="Grand Total Amount In Words" class="total"></h:outputText>
                <p:remoteCommand name="command" actionListener="#{purchaseOrderBean.getjs()}" />


                <h:panelGrid columns="2" style="margin-left:500px;">
                    <h:commandButton class="button" value="save"
                        action="#{purchaseOrderBean.save()}"></h:commandButton>
                    <h:commandButton class="button" value="Cancel" type="reset"></h:commandButton>
                </h:panelGrid>

            </div>
        </div>
        <div id="footer">
        </div>
    </h:form>
</h:body>

</html>

这是我的托管bean方法:

 public void getjs(){
              FacesContext context = FacesContext.getCurrentInstance();
              Map<String, String> map = context.getExternalContext().getRequestParameterMap();
              String value = (String) map.get("param");
              System.out.println("**************** ***************** " + value);
            }

直到$(&#34; #myForm \:grand_Total&#34;)。val(val3 * val4 / 100);在我的xhtml页面工作但命令([{name:&#39; param&#39;,value:val3}]);不工作 问题如何将值传递给托管bean p:remoteCommand getjs方法没有得到param的值请建议我这样做的方法

0 个答案:

没有答案