无法在ajax p:commandbutton update的h:panelgrid值中生成p:datatable

时间:2013-08-19 18:38:16

标签: jsf jsf-2 primefaces prettyfaces commandbutton

我正在开发一个JSF2.1项目,prettyfaces,hibernate 4,primefaces 我在这里遇到问题...我有一个p:commandbutton调用ajax请求,其中条件检查,财务年度是否打开

<p:commandButton id="isFinancialYearSubmitId" value="submit"  update="isFinancialYearBooleanPanelGridId scenarioTabViewId:budgetAnalysisDataTableId" action="#{budgetAnalysisAction.isFinancialYearOpened}"  oncomplete="isFinancialYearOpenedOnComplete();"/>

有3个值...如果财务年度开启则如果财务年度结束则为'1'然后如果无效则为'0'然后'-1' 如果财务年度关闭或无效,则图像会加载一些文本,但问题在这里 如果财政年度开放,那么我想生成一个p:dataTable

<h:panelGrid columns="2" id="isFinancialYearBooleanPanelGridId" styleClass="panelGridCenter" >
<h:column>
<ui:fragment rendered="#{budgetAnalysisAction.budgetFinancialYearBean.financialYearForProposalsBean == '-1'}">
<ui:fragment rendered="#{budgetAnalysisAction.util.errorCode == '-1'}" >
<h:outputText  value="&lt;div class='n_error'>&lt;p>Error . #{budgetAnalysisAction.util.errorMessage}&lt;/p>&lt;/div>" escape="false"/> 
</ui:fragment>
</ui:fragment>
<ui:fragment rendered="#{budgetAnalysisAction.budgetFinancialYearBean.financialYearForProposalsBean == '0'}">
<ui:fragment rendered="#{budgetAnalysisAction.util.errorCode == '-1'}" >
<h:outputText  value="&lt;div class='n_error'>&lt;p>Error . #{budgetAnalysisAction.util.errorMessage}&lt;/p>&lt;/div>" escape="false"/> 
</ui:fragment>
</ui:fragment>
</h:column>
<h:column>
<ui:fragment rendered="#{budgetAnalysisAction.budgetFinancialYearBean.financialYearForProposalsBean == '1'}">
<p:tabView id="scenarioTabViewId" style="width:850px" >
<p:tab title="Scenario One" id="scen"> 
<p:dataTable id="budgetAnalysisDataTableId" editable="true" scrollable="true" scrollWidth="800" resizableColumns="true" value="#{budgetAnalysisAction.budgetScenarioHescoProposalBean.budgetScenarioHescoProposalListBean}" var="budgetScenarioHescoProposalList">
… HERE ARE SOME COLUMNS
</p:dataTable>  
</p:tab>
</p:tabView>
</ui:fragment>
</h:column>     
</h:panelGrid>

当我提交命令按钮时,update =“isFinancialYearBooleanPanelGridId scenarioTabViewId:budgetAnalysisDataTableId” 当财政年度结束或无效时,它将成功处理 但是,当财务年度开启时,它不会生成p:dataTable id =“budgetAnalysisDataTableId值”

但是当我把

<p:tabView id="scenarioTabViewId" style="width:850px" >
<p:tab title="Scenario One" id="scen"> 
<p:dataTable id="budgetAnalysisDataTableId" editable="true" scrollable="true" scrollWidth="800" resizableColumns="true" value="#{budgetAnalysisAction.budgetScenarioHescoProposalBean.budgetScenarioHescoProposalListBean}" var="budgetScenarioHescoProposalList">
… HERE ARE SOME COLUMNS
</p:dataTable>  
</p:tab>
</p:tabView>

以外的

<h:panelGrid columns="2" id="isFinancialYearBooleanPanelGridId" styleClass="panelGridCenter" >

p:dataTable对我来说很好用

任何想法谢谢(Y)

这是我的完整xhtml文件

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">

<!-- <link rel="stylesheet" type="text/css" href="/css/style.css"></link>  --> 
<h:head> 
    <h:outputStylesheet name="style.css" library="css" target="head"/>
    <h:outputScript name="validate.js" library="js" target="head"/> <!--    no need here because this file called by mastertemplate due to insert and define tag of jsf  --> 
    <h:outputScript name="jsf.js" library="javax.faces" target="head" />
    <h:outputStylesheet name="login.css" library="css" target="head"/>




</h:head>
<!--  <body class="main_background"> -->
<h:body >
<p>hello </p>
<ui:composition template="/template/mastertemplate.xhtml">  

    <ui:define name="content">
<f:view>


<div id="main">
            <div class="full_w" style="height: auto; max-width: 1045px; overflow: hidden;">
                <div class="h_title">Formation's Proposal</div>
                    <h:form styleClass="form" prependId="false" id="anaForm">
                        <p:panel id="formationsproposalPenel" header="Analysis The Budget">
                                <div class="divPanel">
                                        <div align="right" class="divContent">
                                                <div align="left" style="margin-top: 10px;">
                                                            <h:panelGrid columns="4" id="isFinancialYearPanelGridId">
                                                                        <h:column>
                                                                                <h:outputLabel value="Enter financial year " />
                                                                        </h:column>
                                                                        <h:column>
                                                                                <p:inputMask id="isFinancialYearFromId" style="width:50px" mask="9999" value="#{budgetAnalysisAction.budgetFinancialYearBean.isFinancialYearFromBean}" /> -
                                                                        </h:column>
                                                                        <h:column>
                                                                                <p:inputMask id="isFinancialYearToId" style="width:50px" mask="9999" value="#{budgetAnalysisAction.budgetFinancialYearBean.isFinancialYearToBean}" />
                                                                        </h:column>
                                                                        <h:column>
                                                                                <p:commandButton id="isFinancialYearSubmitId" value="submit"  update="isFinancialYearBooleanPanelGridId scenarioTabViewId:budgetAnalysisDataTableId" action="#{budgetAnalysisAction.isFinancialYearOpened}"  oncomplete="isFinancialYearOpenedOnComplete();"/>
                                                                        </h:column>
                                                            </h:panelGrid>
                                                <p:separator id="separatorId" style="border:1px solid #b8b8b8;margin-top:5px; width:80%;"/> 

                                                </div>

                                                <h:panelGrid columns="2" id="isFinancialYearBooleanPanelGridId" styleClass="panelGridCenter" >
                                                        <h:column>
                                                                <ui:fragment rendered="#{budgetAnalysisAction.budgetFinancialYearBean.financialYearForProposalsBean == '-1'}">
                                                            <ui:fragment rendered="#{budgetAnalysisAction.util.errorCode == '-1'}" >
                                                                    <h:outputText  value="&lt;div class='n_error'>&lt;p>Error . #{budgetAnalysisAction.util.errorMessage}&lt;/p>&lt;/div>" escape="false"/> 
                                                            </ui:fragment>
                                                        </ui:fragment>
                                                        <ui:fragment rendered="#{budgetAnalysisAction.budgetFinancialYearBean.financialYearForProposalsBean == '0'}">
                                                            <ui:fragment rendered="#{budgetAnalysisAction.util.errorCode == '-1'}" >
                                                                    <h:outputText  value="&lt;div class='n_error'>&lt;p>Error . #{budgetAnalysisAction.util.errorMessage}&lt;/p>&lt;/div>" escape="false"/> 
                                                            </ui:fragment>
                                                        </ui:fragment>

                                                        </h:column>
                                                        <h:column>

                                                             <ui:fragment rendered="#{budgetAnalysisAction.budgetFinancialYearBean.financialYearForProposalsBean == '1'}">
                                                             <p:tabView id="scenarioTabViewId" style="width:850px" >
                                                                <p:tab title="Scenario One" id="scen"> 
                                                                <p:dataTable id="budgetAnalysisDataTableId" editable="true" scrollable="true" scrollWidth="800" resizableColumns="true" value="#{budgetAnalysisAction.budgetScenarioHescoProposalBean.budgetScenarioHescoProposalListBean}" var="budgetScenarioHescoProposalList">

                                                                <!--    <p:ajax event="rowEdit" listener="#{}"/>  -->
                                                                        <p:column headerText="Edit" width="30">
                                                                            <p:rowEditor />
                                                                        </p:column>
                                                                        <p:column headerText="Sub Head Of Accounts" width="150" >
                                                                            <h:outputText value="#{budgetScenarioHescoProposalList.budgetSubHeadOfAccountsBean.subHeadOfAccountNameBean}" />
                                                                        </p:column>
                                                                        <p:column width="150" headerText="Average of #{budgetScenarioHescoProposalList.labelLastThreeYearAvgActualExpBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Actual Expenditure Of #{budgetScenarioHescoProposalList.labelLastThreeYearActualExpenditureBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Actual Expenditure Of #{budgetScenarioHescoProposalList.labelLastTwoYearActualExpenditureBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Actual Expenditure Of #{budgetScenarioHescoProposalList.labelLastYearActualExpenditureBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Average Of Allocated Budget #{budgetScenarioHescoProposalList.labelLastThreeYearAvgAllocateBudgetBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Allocated Budget Of #{budgetScenarioHescoProposalList.labelLastThreeYearAllocateBudgetBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Allocated Budget Of #{budgetScenarioHescoProposalList.labelLastTwoYearAllocateBudgetBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Allocated Budget Of #{budgetScenarioHescoProposalList.labelLastYearAllocateBudgetBean}" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Expected Expenditure" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="Next Year Budget" styleClass="wwrapTh wrapTd">

                                                                        </p:column>
                                                                        <p:column width="150" headerText="" styleClass="wwrapTh wrapTd">

                                                                        </p:column>

                                                                </p:dataTable>  

                                                            </p:tab>
                                                            <p:tab title="Scenario Two">
                                                            </p:tab>
                                                            <p:tab title="Scenario Three">
                                                            </p:tab>
                                                            <p:tab title="Scenario Four">
                                                            </p:tab>

                                                        </p:tabView>



                                                             </ui:fragment>



                                                        </h:column>     
                                                </h:panelGrid>
                                        </div>  
                                </div>
                        </p:panel>
                    </h:form>
            </div>
        </div>


</f:view>       
    </ui:define>

</ui:composition>
</h:body>

<!-- </body> -->
</html>

2 个答案:

答案 0 :(得分:0)

我想将此添加为评论,但也许我发现了您的问题:

在p:commandbutton中你有:

update="isFinancialYearBooleanPanelGridId scenarioTabViewId:budgetAnalysisDataTableId"

不应该(你吃结肠吗?)

update="isFinancialYearBooleanPanelGridId:scenarioTabViewId:budgetAnalysisDataTableId"

答案 1 :(得分:0)

我使用

解决了我的问题

的.java

RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam("budgetFinancialYearBean", this.budgetFinancialYearRefObj);

.xhtml

<p:commandButton id="isFinancialYearSubmitId" value="submit" update="panelGridId scenarioTabViewId:budgetAnalysisDataTableId"  action="#{budgetAnalysisAction.isFinancialYearOpened}"  oncomplete="handleComplete(xhr, status, args); isFinancialYearOpenedOnComplete();"/>

的.js

function handleComplete(xhr, status, args) {  

var financialYearForProposalsBeanVar = args.budgetFinancialYearBean.financialYearForProposalsBean;
    if(financialYearForProposalsBeanVar == 1) {
        //rendering data table
    //  alert('value: '+financialYearForProposalsBeanVar);
        document.getElementById("budgetAnalysisDataTableDivId").style.display = "block";    
    }

}