h:commandButtoon和f:如果没有提供动作属性,则ajax不呈现h:dataTable

时间:2012-11-18 09:53:34

标签: ajax jsf

我有一个带有dataTable的followig表单和一个带有输入字段的编辑部分来操作表数据。我想在单击commandButton后刷新数据表:

<f:ajax>
<h:panelGroup id="timesheet_panel">
    <h:dataTable id="datatable"
            value="#{timesheetController.myTimeSheet}" var="child">
    ......
        <h:column>
        <!-- update editor panel data -->
        <h:commandLink
            action="#{timesheetController.load(child.item['$uniqueid'])}">
                    <h:outputText value="#{message.edit}" />
            <f:ajax
                render=":#{component.parent.parent.parent.parent.clientId}:editorpanel" />
        </h:commandLink>
    </h:column>

    </h:dataTable>

    <!-- Editor  -->
    <h:panelGroup id="editor">
        <h:inputText value="#{timesheetController.workitem.item['_category']}" />

        <h:commandButton action="/mypage"
                    actionListener="#{timesheetController.process('10')}"
            value="Update Tabledata">
            <f:ajax render="datatable" />
        </h:commandButton>
    </h:panelGroup>
</h:panelGroup>
</f:ajax>

注意:我有一个带有h:commandLink的h:列来更新表格下方编辑器面板中显示的数据。

问题是:为什么有必要在编辑器面板中为commandButton提供action属性?如果我没有提供action属性,则f:ajax render =“datatable”将不刷新数据表。 所以在我看来,这里只能使用actionListener来更新后端数据。只有当操作的结果等于当前页面时,操作方法才有效。 任何人都可以解释这种行为吗? 我正在使用GlassFish 3.1.2

1 个答案:

答案 0 :(得分:0)

要刷新表格,您需要至少将您的bean放在 @ViewScoped 中。此外,在设置值之后将重新创建您的beed,以便您获得相同的点。