2

I have a data table that needs to be refreshed upon using an ajax command found in each row.

<div class="authorSection">
    <h:dataTable id="author-table" var="author" value="#{authorPOCBean.getauthors()}">
        <h:column>
            <f:facet name="header">
                <h:outputText value="Org Short Name" />
            </f:facet>
            <h:outputText id="authorOrganizationShortName" value="#author.orgShortName}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="Organization Name" />
            </f:facet>
            <h:outputText id="authorOrganizationName" value="#{author.orgName}" />
        </h:column>
        <h:column>                
            <f:facet name="header">
                <h:outputText value="Location" />                
            </f:facet>
            <h:outputText id="authorLocation" value="#{author.orgLocation}" />
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputText value="author Type" />
            </f:facet>
            <h:outputText id="authorType" value="#{author.authorName}" />
        </h:column>
        <h:column>
            <h:form id="deleteauthorForm">
                <h:commandLink action="#{authorPOCBean.deleteauthor(author)}" value="Delete">                    
                    <f:ajax render=":author-table"/>
                </h:commandLink>
            </h:form>
            <h:form id="setInitialauthorForm">
                <h:commandLink action="#{authorPOCBean.makeInitialauthor(author)}" value="Make Initial"/>                
            </h:form>
        </h:column>
    </h:dataTable>
</div>

When the delete function is used it seems to leave the table unchanged or perhaps renders it with old data? I've got it set now to the first thing the called method does is change the internal array THEN changes the database stuff but it still uses the old data.

Is there something obviously wrong with my code?

I have looked at the below link and tried the recommendations and have no new result. In fact if I surround the table with a form the table won't build right.

JSF- <f:ajax> can't render datatable

Community
  • 1
  • 1
mja
  • 69
  • 1
  • 2
  • 9
  • You have form inside a data table which might not be a valid approach? – SRy Mar 05 '13 at 02:28
  • Ensure that there are no [nested forms](http://stackoverflow.com/questions/7371903/multiple-hform-in-a-jsf-page/7372315#7372315) above the utmost `
    `, no [naming containers](http://docs.oracle.com/javaee/6/api/javax/faces/component/NamingContainer.html) above data table, you are running on Servlet 3.0 Container and that your action is actually hit (no spelling errors, etc.) by putting a breakpoint on the method. Get in touch after you check it.
    – skuntsel Mar 05 '13 at 06:42
  • And show us your bean action methods. – skuntsel Mar 05 '13 at 06:44

1 Answers1

0

Please be noted that you have placed the Delete Button and Make initial Buttons enclosed in a separate form whereas the DataTable component is placed outside the form .

Try having a single form starting at at the start of the table . (ie) Your table component and the two buttons should be enclosed within the same form

and for Ajaxical refresh, the following should work for you .

   <f:ajax render="@form"/>

If for some other reason you cannot use a single form and need multiple forms , Please refer this question How to retain form data in a multi form page

Community
  • 1
  • 1
Muthu Raman
  • 154
  • 2
  • 13
  • This makes the buttons work but now all the special features of the datatable (search, sort, formatting) no longer work. Now it is just a plain unadorned table. Any idea as to why? – mja Mar 05 '13 at 16:39