如何使用 <f:ajax render> 重新渲染 <ui:repeat>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3547581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to re-render <ui:repeat> using <f:ajax render>
提问by Sven
I have implemented a list created by a repeater:
我已经实现了一个由中继器创建的列表:
<ui:repeat value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
and a Button that filters my list:
和一个过滤我的列表的按钮:
<h:commandLink action="#{overviewController.filterNew}">
<h:outputText value="Filter List" />
</h:commandLink>
So, is there an easy way to render only my repeater after clicking the command link (with AJAX) :-)
那么,是否有一种简单的方法可以在单击命令链接(使用 AJAX)后仅呈现我的转发器 :-)
I tried following:
我尝试了以下操作:
<f:ajax render="repeater">
ui:repeat id="repeater" value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
<f:ajax />
<h:commandLink action="#{overviewController.filterNew}">
<h:outputText value="Filter List" />
<f:ajax event="click" render="repeater"/>
</h:commandLink>
but that did not work..
但这不起作用..
Update
更新
<h:form>
ui:repeat id="repeater" value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
<h:commandLink action="#{overviewController.filterNew}">
<h:outputText value="Filter List" />
<f:ajax event="click" render="repeater"/>
</h:commandLink>
</h:form>
doesn't work either... Maybe I hav to put the action method (overviewController.filterNew) into the ajax tag?
也不起作用...也许我必须将操作方法 (overviewController.filterNew) 放入 ajax 标记中?
Update 2
更新 2
<f:ajax event="click" render="repeater">
<h:commandLink action="#{overviewController.filterEBus}">
<h:outputText value="EBusiness" />
</h:commandLink>
</f:ajax>
Doesn't work either!
也不行!
Maybe it's not possible to rerender a repeater ? is there another element like a div tag or something that can be rerendered???
也许不可能重新渲染中继器?是否有另一个元素,如 div 标签或可以重新渲染的东西???
...
...
Thank you for your help
感谢您的帮助
回答by BalusC
The <ui:repeat>itself does not generate any HTML to the output. The <f:ajax render>expects an ID which is present in the HTML DOM tree. Put it in a <h:panelGroup>with an idand reference it instead.
在<ui:repeat>本身不产生任何HTML的输出。所述<f:ajax render>期望的ID,其是存在于HTML DOM树。把它放在一个<h:panelGroup>与id和引用它来代替。
<h:form>
<h:panelGroup id="projects">
<ui:repeat value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
</h:panelGroup>
<h:commandLink action="#{overviewController.filterNew}">
<h:outputText value="Filter List" />
<f:ajax execute="@form" render="projects" />
</h:commandLink>
</h:form>
回答by Bozho
Yes:
是的:
- using Richfaces
<a4j:commandButton reRender="targetId" /> - using JSF 2.0
<f:ajax event="click" render="targetId"> - using Primefaces
<p:ajax>
- 使用 Richfaces
<a4j:commandButton reRender="targetId" /> - 使用 JSF 2.0
<f:ajax event="click" render="targetId"> - 使用 Primefaces
<p:ajax>
回答by Dejell
<f:ajax render="repeater">
ui:repeat id="repeater" value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
<f:ajax />
why did you wrap it with f:ajax? It's redundant in this case.
你为什么用 f:ajax 包装它?在这种情况下它是多余的。
Make sure that your components are surrounded by <h:form>tag
确保你的组件被<h:form>标签包围
<h:form>
<ui:repeat id="repeater" value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
<h:commandLink action="#{overviewController.filterNew}">
<h:outputText value="Filter List" />
<f:ajax event="click" render="repeater"/>
</h:commandLink>
</h:form>
回答by amorfis
How about this:
这个怎么样:
<ui:repeat id="repeater" value="#{projectData.paginator.list}" var="project">
<h:outputText value="#{project.title}" />
</ui:repeat>
<h:commandLink>
<h:outputText value="Filter List" />
<f:ajax render="repeater" listener="#{overviewController.filterNew}" />
</h:commandLink>

