JSF Ajax渲染实际上做什么? [英] What JSF Ajax render actually do?

查看:45
本文介绍了JSF Ajax渲染实际上做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF代码中,我看到了:

In the JSF code, I see this:

...

<h:selectOneMenu id="clientCode" value="#{theBean.clientCodeSelection}">
  <f:selectItem itemValue="" itemLabel="Please select one" />
  <f:selectItems value="#{theBean.clientList}" />
  <f:ajax render="go"/>
</h:selectOneMenu>

...

<h:commandButton id="go" value="Go" immediate="true" >
  <f:ajax render="clientTable" event="click" listener="#{theBean.doSearch}"></f:ajax>
</h:commandButton>

我可以知道<f:ajax render="go"/>的实际作用吗?我最初的假设是渲染 Go按钮,但是我认为它没有我想象的那么严格.如果我错了,请纠正我.

May I know what does <f:ajax render="go"/> actually do? My initial assumption is to render the Go button, but I don't think it is as strict forward as I think. Please correct me if I am wrong.

推荐答案

当Web浏览器中的ajax请求成功完成时,<f:ajax render="go">将使用相对客户端ID go更新JSF组件的生成的HTML表示.基本上,具有相对客户端ID go的JSF组件将位于Web服务器中的JSF组件树中,然后执行,此后其生成的HTML输出将最终出现在ajax响应中.一旦ajax响应在Web浏览器中返回,此HTML输出将确切地在Web浏览器的HTML DOM树中更新.如果JSF组件可以根据提交的表单数据在每个请求的基础上生成不同的HTML内容,这将非常有用.

The <f:ajax render="go"> will update the generated HTML representation of the JSF component with relative client ID go when the ajax request has completed successfully in the webbrowser. Basically, the JSF component with relative client ID go will be located in the JSF component tree in the webserver and then executed, whereafter its generated HTML output will end up in the ajax response. Once the ajax response returns in the webbrowser, exactly this HTML output will be updated in the HTML DOM tree in the webbrowser. This is very useful if the JSF component can generate different HTML content on a per-request basis based on the submitted form data.

请注意,这仅在始终显示 JSF组件(即,其自身或其父级上没有rendered="false")时有效.

Note that this only works if the JSF component is always rendered (i.e. it doesn't have a rendered="false" on itself or its parents).

在您的特定示例中,所生成的HTML表示中基本上没有任何内容可以根据每个请求进行更改.因此,在这种特定情况下,<f:ajax render="go">似乎完全无用.例如,如果您有第二个下拉列表,其可用项目列表取决于当前下拉列表中的选定项目,则在<f:ajax render>中引用它是有意义的,以便在更改当前列表时使用新项目来更新它下拉菜单.

In your particular example, there's basically nothing in the generated HTML representation which could change on a per-request basis. So that <f:ajax render="go"> is in this specific case seemingly completely useless. If you would for example have a second dropdown whose list of available items depends on the selected item of the current dropdown, then it would make sense to reference it in <f:ajax render>, so that it get updated with new items when you change the current dropdown.

这篇关于JSF Ajax渲染实际上做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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