用ajax渲染一个div [英] Rendering a div with ajax
问题描述
我有这个div
<div id="name">
....
</div>
我还有一个按钮可以做到这一点:
<h:commandLink id="bttn" action="#">
<f:ajax render="name"/>
</h:commandLink>
问题是执行时会说没有所谓的名称"组件.有没有一种方法可以使ajax 呈现div而不会将其封装在jsf组件中?
不行.在JSF的幕后,Ajax渲染的工作原理大致如下:
for (String clientIdToRender : clientIdsToRender) {
UIComponent componentToRender = viewRoot.findComponent(clientIdToRender);
// ...
}
但是,由于纯HTML <div>
不是 作为块级别元素".
<h:panelGroup layout="block" id="name">
...
</h:panelGroup>
另请参见:
I have this div
<div id="name">
....
</div>
I also have a button that does this:
<h:commandLink id="bttn" action="#">
<f:ajax render="name"/>
</h:commandLink>
The problem is that when executing, it says that there is no component called "name". Is there a way I can render a div with an ajax without enclosing it within a jsf component?
No, there's no way. Ajax rendering works roughly as follows under JSF's hoods:
for (String clientIdToRender : clientIdsToRender) {
UIComponent componentToRender = viewRoot.findComponent(clientIdToRender);
// ...
}
However, as the plain HTML <div>
is not as a fullworthy JSF component available by UIViewRoot#findComponent()
, JSF can't find anything to generate the updated HTML output for.
You do not necessarily need to wrap it in another JSF component, you can also just use a JSF component which generates already a HTML <div>
element. That is the <h:panelGroup>
component whose layout
attribute is set to block
(as in, "render a block level element").
<h:panelGroup layout="block" id="name">
...
</h:panelGroup>
See also:
这篇关于用ajax渲染一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!