问题描述
我想AJAX更新有条件渲染的成分。
I'm trying to ajax-update a conditionally rendered component.
<h:form>
...
<h:commandButton value="Login" action="#{login.submit}">
<f:ajax execute="@form" render=":text" />
</h:commandButton>
</h:form>
<h:outputText id="text" value="You're logged in!" rendered="#{not empty user}" />
然而,这是行不通的。我可以保证,#{用户}
实际可用。这是怎么造成的,我该怎么解决呢?
However, that does not work. I can assure that #{user}
is actually available. How is this caused and how can I solve it?
推荐答案
这是不可能重新渲染(更新)如果组件本身没有排在首位渲染的成分阿贾克斯。该组件必须始终呈现前阿贾克斯可以重新渲染它。阿贾克斯是使用JavaScript 的document.getElementById()
来查找需要更新的组件。但是,如果JSF没有渲染的成分,JavaScript不能发现任何东西。
It's not possible to re-render (update) a component by ajax if the component itself is not rendered in first place. The component must be always rendered before ajax can re-render it. Ajax is using JavaScript document.getElementById()
to find the component which needs to be updated. But if JSF hasn't rendered the component, JavaScript can't find anything.
敷在它总是呈现一个组件,而不是对其进行更新。
Wrap it in a component which is always rendered and update it instead.
<h:panelGroup id="text">
<h:outputText value="You're logged in!" rendered="#{not empty user}" />
</h:panelGroup>
参见:
- Why我需要巢渲染的成分=&QUOT;#{有些}&QUOT;在另一个组件时,我想AJAX的更新呢?
- Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?
See also:
这篇关于阿贾克斯更新/渲染不会对已呈现的属性的组件工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!