简体   繁体   English

无法在jsf中使用Ajax调用呈现数据表

[英]Datatable not rendering with ajax call in jsf

I have a data table that needs to be refreshed upon using an ajax command found in each row. 我有一个数据表,需要使用在每一行中找到的ajax命令进行刷新。

<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? 使用delete函数时,它似乎使表保持不变还是用旧数据呈现它? 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 JSF- <f:ajax>无法呈现数据表

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 . 请注意,您已将Delete Button和Make Initial Buttons放在单独的表单中,而DataTable组件则放置在表单外部。

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 . 并且对于Ajaxical刷新,以下内容应该适合您。

   <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 如果由于其他原因您不能使用单个表单而需要多个表单,请参考此问题如何在多表单页面中保留表单数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM