0
votes

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

3
try render="tblProject" or render="@form" instead of render=":tblProject"Daniel
render="tblProject" throw exception with unknown id 'tblProject', render="@form" doesn't make sense since datatable not in form.lastcow
what is the full id of the table (view source in your browser)?Daniel
Your table wrapped eventually in some h:form , right ?Daniel
it's not, i have following structure.<h:form>.button.</h:form><h:datatable><h:form>button</h:form><h:form>button</h:form>...</h:datatable>, and the button in first h:form can render datatable with render=":tblProject", but the button within datatable can't. :(lastcow

3 Answers

0
votes

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

0
votes

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.

0
votes

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

Thanks everyone ;)