6

我的 p:dialog 不断加载,我只需要它出现一次。有人知道该怎么做吗?

    <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>
    ...

按钮:

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

LoginBean 中的 login() :

    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;
     }

我有一个 customAuthenticationProvider 在数据库为空时返回“ATIVACAO”,因此我需要打开此对话框来插入数据,但它会不断重新打开(关闭并立即重新打开)。

4

1 回答 1

3
  1. <h:body onload="dialogAtivacao.show();"/>转换为<body>HTML 的标签被加载时,显示弹出窗口。当<body>视图的整页重新加载发生时,标签将被重新加载

  2. <h: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 命令组件:

 <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只触发一次

于 2013-04-30T13:37:31.403 回答