Jsf Primefaces p:对话框继续重新打开

Jsf Primefaces p:对话框继续重新打开,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我的p:对话框不断加载,我需要它只显示一次。有人知道怎么做吗 <h:body style="background: url('img/background/teste/brushed_alu.png')!important" onload="dialogAtivacao.show();"> <script type="text/javascript"> $(document).ready(function() { document.

我的p:对话框不断加载,我需要它只显示一次。有人知道怎么做吗

    <h:body style="background: url('img/background/teste/brushed_alu.png')!important" onload="dialogAtivacao.show();">
    <script type="text/javascript">
    $(document).ready(function() {
        document.getElementById("j_username").focus();
    });
    </script>

    <p:dialog id="dialogAtivar" header="Ativação de empresa"  showEffect="drop" hideEffect="drop" resizable="false"
              widgetVar="dialogAtivacao" modal="true" closable="true" rendered="#{sessionScope['SPRING_SECURITY_LAST_EXCEPTION'].message == 'ATIVACAO'}">
        <ui:include src="pages/ativacao/AtivacaoEmpresa.xhtml"/>
    </p:dialog>
    ...
我有一个customAuthenticationProvider,当数据库为空时返回'ativaco',因此我需要打开此对话框以插入数据,但它会继续重新打开(关闭一个对话框,然后立即重新打开)

  • 转换为加载HTML的
    标记时,显示弹出窗口。重新加载视图的整个页面时,
    标记将重新加载

  • 将在每次单击按钮时触发整页刷新

  • 总之,每次我点击这个按钮,就会重新加载整个页面并显示对话框

    请改用ajax命令组件:

     <p:commandButton id="saveButton" action="#{login.doLogin}" value="  Entrar" styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only botaoEntrar"/>
    
    
    

    这样,ajax请求被触发,
    onload
    只被触发一次

    这里的“on&on”是什么意思?对话框在页面加载时加载?它拒绝关闭?或者它关闭后立即重新打开?正常情况下,什么会触发该对话框?嗨,kolossus,它会关闭一个对话框,然后立即重新打开。谢谢。您需要在此处包含对话框的触发器组件以供上下文使用。我已经编辑了我的帖子。您认为有没有什么地方可以使用
    dialogativaco.show()
    而不是使用
    onLoad
    函数来解决ajax问题,对话框的
    visible
    属性应具有与
    rendered
    属性相同的表达式。当“数据库不再是空的”时,他可以进行完整的页面刷新,而不必担心弹出对话框。@Manuel,这也可以,但它似乎是一个登录页面,我猜OP希望在打开页面时显示对话框。使用
    visible
    attr将产生一个额外的验证参数,以检查页面加载是否为新请求。任何一个都可以。您可以发布它的一个实现
        public String doLogin() throws IOException, ServletException {
               ExternalContext context =  FacesContext.getCurrentInstance().getExternalContext();
               RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check?j_username=" + username + "&j_password=" + password);
               dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());
               FacesContext.getCurrentInstance().responseComplete();
    
               return null;
         }
    
     <p:commandButton id="saveButton" action="#{login.doLogin}" value="  Entrar" styleClass="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only botaoEntrar"/>