在jsf中使用Ajax渲染组件 [英] Render component with ajax in jsf

查看:90
本文介绍了在jsf中使用Ajax渲染组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是,当我将f:ajax的render属性设置为@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);
}

解决方案

使用<f:ajax>,JavaScript用于在HTML DOM树中定位元素并重新呈现它们.但是,如果未将JSF组件呈现到HTML输出中,则HTML DOM树中也没有任何东西可以重新呈现.您应该重新渲染总是渲染的最接近的父组件,或者将其包装在总是渲染的另一个组件(例如<h:panelGroup>)中,然后重新渲染.

另请参见:

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);
}

解决方案

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:

这篇关于在jsf中使用Ajax渲染组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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