JSF-< F:AJAX>无法呈现的数据表 [英] JSF- <f:ajax> can't render datatable

查看:261
本文介绍了JSF-< F:AJAX>无法呈现的数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表里面有一个删除按钮,在每一行, 我希望当在该行的数据被删除,重新呈现表。

I have a datatable which has a "delete" button at each row, and I want to re-render the table when the data at the row is deleted.

但我不能让 F:AJAX 正常工作

下面是数据表在页面的facelet:

Here is the datatable at facelet page:

<h:form>
 <h:dataTable  value="#{adminPanelBean.activitiesList}" var="activityItem" id="allActivities"
                          styleClass="datatable" cellpadding="2" cellspacing="4"
                          columnClasses="ColName,colType,colTime,colPlace,colSummary" >
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Etkinlik"/>
                    </f:facet>
                    <h:outputText value="#{activityItem.name}  "/>

                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Türü"/>
                    </f:facet>
                    <h:outputText value="#{activityItem.type}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Tarih "/>
                    </f:facet>
                    <h:outputText value="#{activityItem.time}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Yer "/>
                    </f:facet>
                    <h:outputText value="#{activityItem.place}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Açıklama "/>
                    </f:facet>
                    <h:outputText value="#{activityItem.summary}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="&nbsp;"/>
                    </f:facet>
            **<h:commandButton  value="Delete activity" onclick="if(confirm(' Delete #{activityItem.name} ?'))return true; else return false;"  action="#{adminPanelBean.deleteActivity(activityItem.id)}">&nbsp;
                    <f:ajax event="click" render="allActivities" execute="@all" immediate="true"/>
            <f:param name="activityId" value ="#{activityItem.id}"  />
               </h:commandButton>**
             </h:column>
            </h:dataTable>
        </h:form>

当我刷新页面,我看行被删除。但我希望它是动态完成的。

When I refresh the page, I see the row is deleted. But I want it to be done dynamically.

推荐答案

在action方法,你需要从列表中删除的项目,以及(因此不仅从DB)。我建议,仅通过ID的整个项目,而不是让你可以使用列表#删除()方法。

In the action method you need to remove the item from the list as well (and thus not only from the DB). I'd suggest to pass the whole item instead of only the ID so that you can utilize List#remove() method.

action="#{adminPanelBean.deleteActivity(activityItem)}">

所以,你可以做

So that you can do

public void deleteActivity(Activity activity) {
    activitiesList.remove(activity);
    // ...
}


无关以具体的问题,他们的方式你如何使用确认()是pretty的笨拙。


Unrelated to the concrete problem, they way how you used confirm() is pretty clumsy.

onclick="if(confirm(' Delete #{activityItem.name} ?'))return true; else return false;"

该函数返回一个布尔了。你并不需要,如果测试所获得的在布尔值,以返回另一个布尔。只需将其简化为如下:

That function returns a boolean already. You do not need to test the obtained boolean within an if in order to return another boolean. Just simplify it as follows:

onclick="return confirm('Delete #{activityItem.name}?')"

这篇关于JSF-&LT; F:AJAX&GT;无法呈现的数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆