【问题标题】:Can not generate p:datatable in h:panelgrid values on ajax p:commandbutton update无法在 ajax p:commandbutton 更新的 h:panelgrid 值中生成 p:datatable
【发布时间】:2013-08-19 18:38:16
【问题描述】:

我正在开发一个 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>

【问题讨论】:

    标签: jsf jsf-2 primefaces prettyfaces commandbutton


    【解决方案1】:

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

    在 p:commandbutton 你有:

    update="isFinancialYearBooleanPanelGridId scenarioTabViewId:budgetAnalysisDataTableId"
    

    不应该是(你吃结肠了吗?)

    update="isFinancialYearBooleanPanelGridId:scenarioTabViewId:budgetAnalysisDataTableId"
    

    【讨论】:

      【解决方案2】:

      我已经解决了我的问题

      .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";    
          }
      

      }

      【讨论】:

        猜你喜欢
        • 2013-05-22
        • 2012-07-25
        • 1970-01-01
        • 1970-01-01
        • 2012-09-13
        • 1970-01-01
        • 2012-10-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多