How can I prevent page refresh on click of <h:commandLInk>

老子叫甜甜 提交于 2019-12-06 07:19:49

Since i see your using primefaces for the calendar component, you may want to use the primefaces commandbutton and datatable as well. The primefaces components all play pretty nice together.

From my example below, you can see that i gave your datatable an id and on the commandLink, i've added an update attribute to update the datatable after the action is called. By default, primefaces has an ajax attribute that is set to true on the commandLinks.

<p:dataTable id="myTable" value="#{person.IssueList}" var="p" >
    <p:column style="width: 20px" headerText="Issue">
         <p:commandLink value="#{p.IssueDesc}"/>
    </p:column>

    <p:column style="width: 20px" headerText="Reporting Date">
         <p:calendar  value="#{p.issuerepDt}" rendered="#{p.editable}"                 id="CalendarId"/>                
         <h:outputText value="#{p.issuerepDt}" rendered="#{not p.editable}" />
    </p:column>

    <p:column headerText="Action">
         <p:commandLink  value="Edit" action="#{person.editAction(p)}" update="myTable"/>
    </p:column>
</p:dataTable>

I would try to use the listener of f:ajax instead of action of h:commandLink:

<h:commandLink value="Edit">
    <f:ajax listener="#{person.editAction(p)}" execute="@form" render="dataTableId calendarId" />          
</h:commandLink>  

Also, pay attention to what you want to render after the ajax.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!