Reza
Reza

Reputation: 2036

Ajax Call method more than Once in jsf

I have a Composit Component that use Ajax on <p:selectOneButton/>, when Ajax call the actionListener on <p:commandButton/> it calls 10 times then run the method. I think the problem cause by <p:dataGrid/> because when i put my <p:commandButtton/> out of <p:dataGrid/> access , it works normally but when i used it in <p:dataGrid/> The Ajax call actionListener more than once.

Here is the .xhtml:

<table style="width: 100%">
    <tr>
        <td><p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
                <f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" />
                <f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />
                <f:ajax event="change" render="requestDataGrid" />
            </p:selectOneButton></td>
    </tr>
    <tr>
        <td><p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1"
                rows="2">
                <p:column>
                    <div>
                        <table border="0" width="100%">
                            <tr>
                                <td><p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}" /></td>
                                <td>
                                    <div>
                                        <table border="0" width="100%">
                                            <tr>
                                                <td><h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}" /></td>
                                            </tr>
                                            <tr>
                                                <td><h:outputLabel value="#{tBusinessPartnerReques`enter code here`tInfo.partySender_fullName}" /></td>
                                            </tr>
                                        </table>
                                    </div>
                                </td>
                                <td><p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}" process="@this"
                                        actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}">
                                    </p:commandButton></td>
                                <td><p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"
                                        actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}">
                                    </p:commandButton></td>
                            </tr>
                        </table>
                    </div>
                    <hr />
                </p:column>
            </p:dataGrid> <p:panel>


            </p:panel></td>
    </tr>
</table>

How can i fix this problem?

Thanks.

Upvotes: 3

Views: 518

Answers (1)

Tiago Vieira Dos Santos
Tiago Vieira Dos Santos

Reputation: 1004

I think you can use the options partialSubmit and process in your ajax request to process only the necessary information, something like this:

<p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
    <f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" />
    <f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />

    <f:ajax event="change" render="requestDataGrid" partialSubmit="true" process="@this" />
</p:selectOneButton>

if this solved your problem you can see more in the primefaces showcase:

Partial submit

Partial process

Upvotes: 2

Related Questions