Rounak
Rounak

Reputation: 181

primefaces command button action invoked after datatable load

I am facing a problem with primefaces command button and datatable. I have two buttons inside the datatable. when I click on the button everytime datatable loaded first and then button action invoked. I just want to avoid the datatable loading when button is clicked.

 <p:dataTable id="alphaTable" var="cs" binding="#{challengeSetBean.alphaChallengeSetTable}"
                        value="#{challengeSetBean.challengeSet}" styleClass="myTable"
                        style="list-style-type:none;width:600px;border:1px;" >

                <p:column id="col" style="width:20px;font-size:12px;padding-left:7px;padding-bottom:7px;padding-top:7px;">
                  ..................
                                      ................      
                </p:column>

                <p:column  style="width:28px;font-size:9px;padding-left:7px;padding-bottom:7px;padding-top:7px;">

                        <p:commandButton value="#{msg.updateAccount_reset}" action="#{challengeSetBean.editAnswer()}" immediate="true" rendered="#{!cs.editMode}" process="@this" update="col" >
                        </p:commandButton>
                        <p:commandButton value="#{msg.common_save}" action="#{challengeSetBean.saveAnswers()}" rendered="#{cs.editMode}" ajax="true" immediate="true" update="@form"/>
                        <p:commandButton value="#{msg.cancel}" action="#{challengeSetBean.cancelAnswer()}" rendered="#{cs.editMode}" ajax="true" immediate="true" update="@form"/>
                        <p:commandButton value="#{msg.common_delete}" action="#{challengeSetBean.deleteAnswer()}" rendered="#{!cs.editMode}"  immediate="true" update="@form"/>

            </p:column>
    </p:dataTable>   

Upvotes: 0

Views: 338

Answers (1)

BalusC
BalusC

Reputation: 1108722

Put the bean in the view scope so that it would be instantiated only once on initial GET request and be reused on subsequent postbacks. Remove the binding attribute from the <p:dataTable> so that the view scoped bean won't be recreated due to chicken-egg JSF issue 1492. Now you can just load the challengeSet in the (post)constructor of the bean. It won't be invoked during subsequent postbacks.

See also:

Upvotes: 1

Related Questions