简体   繁体   中英

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. I'm struggling to get something working. I'm using PrimeFaces and I have a tabview which contains 5 tabs. In one of those tabs I have a dataTable which has several rows and columns. 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. 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. 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

<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.

<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. Is there any POST Request submitted? Is any Action/Setter called?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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