jsf中使用ajax渲染组件

发布于 2024-12-20 23:18:47 字数 968 浏览 2 评论 0原文

问题是,当我将 f:ajax 的渲染属性设置为 @form 时,btnCreateCSV 正确渲染。但是,如果我将其更改为按钮的 id,则不会发生任何情况。我想知道,我该如何解决这个问题。 这是我的 xhtml 代码:

<h:panelGrid layout="block">
            <h:commandButton value="View SQL" action="#{sparqlQueryBean.convert}" id="btnViewSql">
                <f:ajax execute="txtQuery btnCreateCSV" render="btnCreateCSV txtSqlQuery" onevent="waiting" listener="#{sparqlQueryBean.generateCommands}"></f:ajax>
            </h:commandButton>
            <h:commandButton value = "CSV" action = "#{sparqlQueryBean.createCSV}" id = "btnCreateCSV" rendered="#{sparqlQueryBean.showCSV == true}">
                <f:ajax execute="@none" render = "@none" onevent="waiting"></f:ajax>
            </h:commandButton>

这是我的 bean 类。在generateCommands方法中,showCSV的值设置为true。但这不起作用。

    public void generateCommands (AjaxBehaviorEvent event) {
    this.setShowCSV(true);
}

The problem is, when I set the render attribute of f:ajax to @form the btnCreateCSV render correctly. But, if I change it to the id of button nothing happen. I wonder to know, how can I solve this problem.
This is my xhtml code :

<h:panelGrid layout="block">
            <h:commandButton value="View SQL" action="#{sparqlQueryBean.convert}" id="btnViewSql">
                <f:ajax execute="txtQuery btnCreateCSV" render="btnCreateCSV txtSqlQuery" onevent="waiting" listener="#{sparqlQueryBean.generateCommands}"></f:ajax>
            </h:commandButton>
            <h:commandButton value = "CSV" action = "#{sparqlQueryBean.createCSV}" id = "btnCreateCSV" rendered="#{sparqlQueryBean.showCSV == true}">
                <f:ajax execute="@none" render = "@none" onevent="waiting"></f:ajax>
            </h:commandButton>

And it's my bean class. In generateCommands method, the value of showCSV set to true. But it dosn't work.

    public void generateCommands (AjaxBehaviorEvent event) {
    this.setShowCSV(true);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苄①跕圉湢 2024-12-27 23:18:47

通过 ,JavaScript 用于定位 HTML DOM 树中的元素并重新呈现它们。但是,如果 JSF 组件未呈现到 HTML 输出中,那么 HTML DOM 树中也没有任何内容可以重新呈现。您应该重新渲染始终渲染的最接近的父组件,或者将其包装在始终渲染的另一个组件(例如 )中并重新渲染。

另请参阅:

With <f:ajax>, JavaScript is used to locate elements in the HTML DOM tree and re-render them. But if a JSF component is not rendered into the HTML output, then there's also nothing in the HTML DOM tree to re-render. You should either re-render its closest parent component which is always rendered instead, or wrap it in another component (e.g. <h:panelGroup>) which is always rendered and re-render it instead.

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文