Primefaces lightBox closes at click on commandLink

倖福魔咒の 提交于 2019-12-12 01:45:32

问题


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>

回答1:


Use an ajax (asynchronous) request instead of a synchronous request:

<h:commandLink ...>
    <f:ajax ... />
</h:commandLink>

or as you're using PrimeFaces already, just use <p:commandLink> instead (it uses by default already ajax):

<p:commandLink ... />

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" />


来源:https://stackoverflow.com/questions/13048637/primefaces-lightbox-closes-at-click-on-commandlink

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!