问题描述
这只是一个简单的Primefaces灯箱,我想在其中使用commandLinks.不幸的是,当我单击commandLink时,它只是关闭了.有没有办法让lightBox保持打开状态?
It's just a simple Primefaces lightBox I want to use commandLinks in. Unfortunately it simply closes, when I click a commandLink. Is there a way to keep the lightBox open?
以下是我的代码的示例:
Here an example of what my code looks like:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" template="template.xhtml">
<ui:define name="content">
<p:lightBox>
<h:outputLink value="#">
<h:outputText value="open lightbox" />
</h:outputLink>
<f:facet name="inline">
<h:form>
<h:commandLink>
commandLink
</h:commandLink>
</h:form>
</f:facet>
</p:lightBox>
</ui:define>
</ui:composition>
推荐答案
使用ajax(异步)请求代替同步请求:
Use an ajax (asynchronous) request instead of a synchronous request:
<h:commandLink ...>
<f:ajax ... />
</h:commandLink>
或当您已经在使用PrimeFaces时,只需改用<p:commandLink>
(默认情况下已使用ajax):
or as you're using PrimeFaces already, just use <p:commandLink>
instead (it uses by default already ajax):
<p:commandLink ... />
使用ajax时,默认情况下不会执行任何新的页面替换操作(基本上会将任何内容重置"为默认值).在<f:ajax>
的情况下,可以通过render
属性来判断组件树的哪些部分应在客户端进行更新,而在<p:commandLink>
中应通过update
属性进行更新.例如.如果只想渲染/更新父表单,请使用@form
.例如
With ajax, by default no fresh page replacement with the response is performed (which basically "resets" anything to defaults). You can in case of <f:ajax>
tell by render
attribute which parts of the component tree should be updated in the client side and in <p:commandLink>
by the update
attribute. E.g. if you want to render/update the parent form only, use @form
. E.g.
<p:commandLink ... update="@form" />
这篇关于单击CommandLink即可关闭Primefaces lightBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!