简体   繁体   中英

jsf2 f:ajax render issue in datatable

I have a datatable and for each line have a delete linkcommand, as following:

<h:dataTable value='#{glbProjectDtoList}' var='projectDto'
    binding='#{projectController.projectDataTable}' styleClass='display'
    id='tblProject' rowClasses='gradeA, gradeA'
    columnClasses='projectTableName, projectTableProgress, projectTableAction'>
    ......
    <h:commandLink
        action="#{projectController.delete(projectDto.projectId)}">
        <img class="btnDeleteProject mr5"
            src="#{request.contextPath}/resources/images/icons/dark/trash.png" />
        <f:ajax execute="@form"
            onevent="function(data) {deleteProjectEventHandler(data);}"
            render=":tblProject" />
    </h:commandLink>
    ......
</h:dataTable>

The delete function works fine, but the whole datatable is not reRendered, is it because the action nested in data table or by some other reason?


Update :

It's not working, after remove (:), throw following exception:

    javax.faces.FacesException: <f:ajax> contains an unknown id 'tblProject' - cannot locate it in the context of the component j_idt68

means without (:), the element must be in same h:form tag.


Thanks in advance.

-Cow

Remove the : in front of the id:

<f:ajax execute="@form" onevent="function(data) {deleteProjectEventHandler(data);}" render="tblProject"/>

If the id starts with a separator character (usually : ) the component is searched from the root component, otherwise it is searched from the next NamingContainer .

Have a look at the javadoc for more information: UIComponent.findComponent

This is possibly happening because the id of the datatable is not found in the viewroot when component state is getting refreshed.

To find out the exact ID by which this component is present on the viewroot, please check the page source and find out the ID by which this datatable is rendered.

You need to use the same ID as those found in the viewSource to allow the component to be visible in viewRoot when the state is changed.

Alternatively, UIComponent.findComponent will also help and if ID you are specifying is correct it will return you the UIComponent instance else it will return null.

I have go another approach, use hiding form outside of the table. It works.

Thanks everyone ;)

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