窗体中的所有命令链接在ajax请求后停止工作

时间:2016-02-26 16:19:49

标签: jsf primefaces

所以我最初有一个

    <h:selectBooleanCheckbox value="#salesExpenseController.addSalesExpense.fixed}" >
<h:ajax event="change" listener="#{salesExpenseController.checkFixed()}" render = "addBidPrice addBidTotal" />
</h:selectBooleanCheckbox>

听众功能:

public String checkFixed() {
        if (this.getAddSalesExpense().getFixed()) {
            if (this.subOperation.equals(_add)) {
                getAddSalesExpense().setBidPrice(BigDecimal.ZERO);
            }
            if (this.subOperation.equals(_edit)) {
                getEditSalesExpense().setBidPrice(BigDecimal.ZERO);
            }

        } else {
            if (this.subOperation.equals(_add)) {
                getAddSalesExpense().setBidTotal(BigDecimal.ZERO);
            }
            if (this.subOperation.equals(_edit)) {
                getEditSalesExpense().setBidTotal(BigDecimal.ZERO);
            }

        }


        return _viewTimberSale;
    }

每当我点击我的复选框时,该表单中的所有其他命令链接都不起作用。我在checkFixed()中放置了一个System.out.println(),并且ajax请求没有到达该函数或发出任何错误,表现得一无所获。

我通过将复选框更改为:

来解决此问题
<h:selectBooleanCheckbox value="#{salesExpenseController.addSalesExpense.fixed}" >
                                    <p:ajax event="change" listener="#{salesExpenseController.checkFixed()}" update = "addBidPrice addBidTotal" />
                                </h:selectBooleanCheckbox>

一切都运转正常,应该如何。

什么是可能的解释?

这是表单的错误部分,我无法发布整个表单超过30,000个字符:

<!-- START SALES EXPENSE -->
                    <h:panelGroup layout="block" rendered="#{timberSaleController.operation.equals(timberSaleController.saleExpense)}">
                        <h1>Sale Expense</h1>
                        <h:panelGroup layout="block">
                            <h:commandLink styleClass="actionLinkButton" value="#{messages.Link_add}" action="#{salesExpenseController.prepareAddSalesExpense(timberSaleController.selected)}" rendered="#{salesExpenseController.subOperation == null}" />
                            <h:commandLink styleClass="actionLinkButton" value="#{messages.Link_cancel}" action="#{salesExpenseController.resetValues()}" rendered="#{salesExpenseController.subOperation != null}"  />
                            <br/>
                            <br/>
                        </h:panelGroup>



                        <!--SALES EXPENSE TABLE -->
                        <h:panelGroup layout="block" rendered="#{salesExpenseController.subOperation == null}">
                            <h:dataTable value="#{salesExpenseController.getSaleList(timberSaleController.selected)}" var="exp" 
                                         border="0" 
                                         cellpadding="3" 
                                         cellspacing="0" 
                                         rowClasses="jsfcrud_odd_row,jsfcrud_even_row" 
                                         rules="all" 
                                         style="border:solid 1px; text-align: center;"
                                         rendered ="#{salesExpenseController.getSaleList(timberSaleController.selected).size() > 0}"
                                         >
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_description}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.description}" >
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_category}" />
                                    </f:facet>
                                    <h:outputText value="#{timberSaleController.formatString(exp.expenseCategory)}" >
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_fixedPrice}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.fixed}" >

                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_bidPrice}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.bidPrice}" >
                                        <f:convertNumber integerOnly="true" type="currency" />
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_bidTotal}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.bidTotal}" >
                                        <f:convertNumber integerOnly="true" type="currency" />
                                    </h:outputText>
                                </h:column>
                                <h:column rendered = "#{exp.actualPrice != null}">
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_actualPrice}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.actualPrice}" >
                                        <f:convertNumber integerOnly="true" type="currency" />
                                    </h:outputText>
                                </h:column>
                                <h:column rendered = "#{exp.actualTotal != null}">
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_actualTotal}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.actualTotal}" >
                                        <f:convertNumber integerOnly="true" type="number" />
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_lastEdited}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.lastEdited}" >
                                        <f:convertDateTime type="date" dateStyle="short" />
                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="#{messages.Title_lastEditedBy}" />
                                    </f:facet>
                                    <h:outputText value="#{exp.lastEditedBy}" >

                                    </h:outputText>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">
                                        <h:outputText value="&nbsp;" />
                                    </f:facet>
                                    <h:commandLink value="#{messages.Link_edit}" action ="#{salesExpenseController.editSalesExpense(exp)}" />
                                    <br/>
                                    <h:commandLink value="#{messages.Link_complete}" action="#{salesExpenseController.prepareCompleteSalesExpense(exp)}" />
                                </h:column>
                            </h:dataTable>
                            <br/>
                            <br/>
                            <br/>

                            <h:panelGroup layout="block">
                                <table
                                    border="0" 
                                    cellpadding="3" 
                                    cellspacing="0" 
                                    rowClasses="jsfcrud_odd_row,jsfcrud_even_row" 
                                    rules="all" 
                                    style="border:solid 1px; text-align: center;"
                                    >
                                    <tr>
                                        <th>Categories</th>
                                        <th>Average Bid Price</th>
                                        <th>Bid Total</th>
                                    </tr>
                                    <ui:repeat value="#{salesExpenseController.getDistinctCategoriesBySale(timberSaleController.selected)}" var="cat">
                                        <tr>
                                            <td>
                                                <h:outputText value="#{timberSaleController.formatString(cat)}" />
                                            </td>
                                            <td>
                                                <h:outputText value="#{salesExpenseController.getAverageExpensePriceByCategoryAndSale(cat , timberSaleController.selected)}" >
                                                    <f:convertNumber integerOnly="true" type="currency"/>
                                                </h:outputText>
                                            </td>
                                            <td>
                                                <h:outputText value="#{salesExpenseController.getTotalExpenseByCategoryAndSale(cat, timberSaleController.selected)}" >
                                                    <f:convertNumber integerOnly="true" type="currency"/>
                                                </h:outputText>
                                            </td>
                                        </tr>
                                    </ui:repeat>
                                    <tr>
                                        <td>
                                            <h:outputText value ="Totals" />
                                        </td>

                                        <td>
                                            <h:outputText value ="#{salesExpenseController.getAverageBidPriceBySale(timberSaleController.selected)}" >
                                                <f:convertNumber integerOnly="true" type="currency"/>
                                            </h:outputText>
                                        </td>
                                        <td>
                                            <h:outputText value ="#{salesExpenseController.getTotalBidTotalBySale(timberSaleController.selected)}" >
                                                <f:convertNumber integerOnly="true" type="currency"/>
                                            </h:outputText>
                                        </td>
                                    </tr>
                                </table>

                            </h:panelGroup>



                        </h:panelGroup>


                        <!--SALES EXPENSE ADD -->
                        <h:panelGroup layout="block" rendered="#{salesExpenseController.subOperation.equals(timberSaleController.getAdd())}">
                            <h:panelGrid columns="3">
                                <h:outputLabel value="#{messages.Title_description}" />
                                <h:inputTextarea value="#{salesExpenseController.addSalesExpense.description}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Title_category}" />
                                <h:selectOneMenu value="#{salesExpenseController.addSalesExpense.expenseCategory}">
                                    <f:selectItems value="#{timberSaleController.dropDownHelper.getExpenseTypeSelectOne()}" />
                                </h:selectOneMenu>
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_fixed}" />
                                <h:selectBooleanCheckbox value="#{salesExpenseController.addSalesExpense.fixed}" >
                                    <p:ajax event="change" listener="#{salesExpenseController.checkFixed()}" update = "addBidPrice addBidTotal" />
                                </h:selectBooleanCheckbox>
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_bidPrice}" />
                                <h:inputText id="addBidPrice" value="#{salesExpenseController.addSalesExpense.bidPrice}" disabled="#{salesExpenseController.addSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_bidTotal}" />
                                <h:inputText id="addBidTotal" value="#{salesExpenseController.addSalesExpense.bidTotal}" disabled="#{!salesExpenseController.addSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:commandLink styleClass="actionLinkButton" value="#{messages.Link_add}" action="#{salesExpenseController.addSaleExpenseToSale()}" />
                            </h:panelGrid>
                        </h:panelGroup>

                        <!--SALES EXPENSE EDIT -->
                        <h:panelGroup layout="block" rendered="#{salesExpenseController.subOperation.equals(timberSaleController.getEdit())}">
                            <h:panelGrid columns="3">
                                <h:outputLabel value="#{messages.Title_description}" />
                                <h:inputTextarea value="#{salesExpenseController.editSalesExpense.description}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Title_category}" />
                                <h:selectOneMenu value="#{salesExpenseController.editSalesExpense.expenseCategory}">
                                    <f:selectItems value="#{timberSaleController.dropDownHelper.getExpenseTypeSelectOne()}" />
                                </h:selectOneMenu>
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_fixed}" />
                                <h:selectBooleanCheckbox value="#{salesExpenseController.editSalesExpense.fixed}" >
                                    <p:ajax event="change" listener="#{salesExpenseController.checkFixed()}" update="editBidPrice editBidTotal" />
                                </h:selectBooleanCheckbox>
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_bidPrice}" />
                                <h:inputText id="editBidPrice" value="#{salesExpenseController.editSalesExpense.bidPrice}" disabled="#{salesExpenseController.editSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_bidTotal}" />
                                <h:inputText id="editBidTotal" value="#{salesExpenseController.editSalesExpense.bidTotal}" disabled="#{!salesExpenseController.editSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:commandLink styleClass="actionLinkButton" value="#{messages.Link_complete}" action="#{salesExpenseController.completeEditSalesExpense()}" />
                                <h:commandLink styleClass="actionLinkButton" value="#{messages.Link_destroy}" action="#{salesExpenseController.destroyEditSalesExpense()}" />
                            </h:panelGrid>
                        </h:panelGroup>

                        <!--
                        COMPLETE LOG SALE
                        -->
                        <h:panelGroup layout="block" rendered="#{salesExpenseController.subOperation.equals(timberSaleController.getComplete())}">
                            <h:panelGrid columns="3">
                                <h:outputLabel value="#{messages.Title_description}" />
                                <h:inputTextarea disabled="true"  value="#{salesExpenseController.completeSalesExpense.description}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Title_category}" />
                                <h:selectOneMenu disabled="true" value="#{salesExpenseController.completeSalesExpense.expenseCategory}">
                                    <f:selectItems value="#{timberSaleController.dropDownHelper.getExpenseTypeSelectOne()}" />
                                </h:selectOneMenu>
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_fixed}" />
                                <h:selectBooleanCheckbox disabled="true" value="#{salesExpenseController.completeSalesExpense.fixed}" >
                                    <p:ajax event="change" listener="#{salesExpenseController.checkFixed()}" update="" />
                                </h:selectBooleanCheckbox>
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_bidPrice}" />
                                <h:inputText  value="#{salesExpenseController.completeSalesExpense.bidPrice}" disabled="#{salesExpenseController.completeSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_actualPrice}" />
                                <h:inputText value="#{salesExpenseController.completeSalesExpense.actualPrice}" disabled ="#{salesExpenseController.completeSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_bidTotal}" />
                                <h:inputText  value="#{salesExpenseController.completeSalesExpense.bidTotal}" disabled="#{!salesExpenseController.completeSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />
                                <h:outputLabel value="#{messages.Label_actualTotal}" />
                                <h:inputText value="#{salesExpenseController.completeSalesExpense.actualTotal}" disabled ="#{!salesExpenseController.completeSalesExpense.fixed}" />
                                <h:outputText value="&nbsp;" />


                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:outputText value="&nbsp;" />
                                <h:commandLink styleClass="actionLinkButton" value="#{messages.Link_complete}" action="#{salesExpenseController.completeCompleteSalesExpense()}" />
                            </h:panelGrid>
                        </h:panelGroup>




                    </h:panelGroup>
                    <!-- END ADD SALESEXPENSE -->

1 个答案:

答案 0 :(得分:0)

我不知道primeFaces以及它如何执行ajax命令,但标准的ajax监听器方法不应该返回任何对象。但是这样的事情:

public final void checkFixed(AjaxBehaviorEvent event){
     .....
}

你可以这样使用它:

listener="#{salesExpenseController.checkFixed}"

因此,如果您的视图因任何Java异常(如未找到methode等)而抛出任何JS错误,则此JS错误将分解所有commandLinks /按钮等。也许primeFaces接受像你这样的监听器的方法,所以当你使用primefaces ajax命令时你不会得到任何错误。