jsf中使用ajax渲染组件
问题是,当我将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
通过
,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: