简体   繁体   English

如何使用selectBooleanCheckbox提交JSF PrimeFaces表单而不刷新页面?

[英]How to submit JSF PrimeFaces form with selectBooleanCheckbox without refreshing the page?

I'm using JSF with PrimeFaces to make an application as an assignment for college. 我将JSF与PrimeFaces结合使用,以进行大学作业。 I'm struggling to get something working. 我正在努力工作。 I'm using PrimeFaces and I have a tabview which contains 5 tabs. 我正在使用PrimeFaces,并且有一个Tabview,其中包含5个选项卡。 In one of those tabs I have a dataTable which has several rows and columns. 在这些标签之一中,我有一个dataTable,其中有几行和几列。 This all works fine, but the problem is that I want to submit the form without rerendering the (entire page). 一切正常,但问题是我想提交表单而不重新呈现(整个页面)。 The thing is, every column in the dataTable has a selectBooleanCheckbox, and when that checkbox is selected, a button should disappear. 事实是,dataTable中的每一列都有一个selectBooleanCheckbox,并且当选中该复选框时,按钮应该消失。 If it's unselected the button should appear. 如果未选中,则应显示按钮。 This works fine with onchange="this.form.submit()" or onclick="this.form.submit()" but it refreshes the entire application, and it causes the first tab to be selected, rather than the one I was at. 可以在onchange =“ this.form.submit()”或onclick =“ this.form.submit()”上正常工作,但它会刷新整个应用程序,并导致第一个选项卡被选中,而不是我之前选择的选项卡在。 So I'm looking for a solution to be able to submit and re-render some stuff without refreshing the entire program. 因此,我正在寻找一种解决方案,以能够提交和重新呈现某些内容而无需刷新整个程序。 This is my code: 这是我的代码:

<body>
    <h:form id="customerForm">
        <p:dataTable id="customerlist" var="c" value="#{customerBean.customerList}">
            <p:column>
                <f:facet name="header">Select</f:facet>
                <center>
                    <p:selectBooleanCheckbox value="#{c.selected}" onchange="this.form.submit()"/>
                </center>
            </p:column>
        </p:dataTable>
        <h:commandButton id="testtest" value="test" rendered="#{customerBean.numberSelected() == 0}"/>
    </h:form>
</body>

I removed most of the columns for the sake of simplicity. 为了简单起见,我删除了大多数列。 What is the solution to this? 有什么解决方案? I've tried using ajax, but that didn't work 我已经尝试过使用Ajax,但这没用

<p:selectBooleanCheckbox value="#{c.selected}">
    <f:ajax event="click" execute="@form" render="@none"/>
</p:selectBooleanCheckbox>

Do you really need to submit the whole form? 您真的需要提交整个表格吗? If it's enough that the view is being rerenderd try just to update the form. 如果足以重新渲染视图,请尝试仅更新表单。 For that you can use the primefaces ajax event. 为此,您可以使用primefaces ajax事件。

<p:selectBooleanCheckbox value="#{c.selected}">
    <p:ajax update="@form"/>  
</p:selectBooleanCheckbox>

If this does not work, please tell us what "..ajax, didn't work" exactly mean. 如果这不起作用,请告诉我们“ ..ajax,不起作用”的确切含义。 Is there any POST Request submitted? 是否提交了任何POST请求? Is any Action/Setter called? 有人叫“行动/设定者”吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM