Jsf HttpServletResponse在重定向时调用Html正文onLoad

Jsf HttpServletResponse在重定向时调用Html正文onLoad,jsf,Jsf,我有下面的html页面 <html 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">

我有下面的html页面

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

          <h:head>

            </h:head>

       <h:body  onload="#{login.activateAccount()}" >
        <h:form  id="formRegister">
         <p:panel  style="border:none;  width: 0px; height: 0px; margin-left:-15px ; " id="panelMesaje"> </p:panel>
        </h:form>
       </h:body>   
    </html>
在该方法中,如果一切正常,将呈现primefaces对话框

  private void addActivatedInfoMessage(String text) {
        UIComponent panel = ComponentUtils.findComponent("panelMesaje");
        Dialog dialogx=(Dialog) ComponentUtils.findComponent("infoMessageDialog");
        if (ComponentUtils.findComponent("infoMessageDialog") != null) {
        panel.getChildren().remove(dialogx);

        }
            int panelHeight=text.trim().length()/2;
            Dialog dialog = new Dialog();
            dialog.setStyleClass("clasaDialogInfo");
            dialog.setResizable(false); 
            dialog.setDynamic(true);
            dialog.setClosable(false);
            dialog.setWidgetVar("infoMessageDialog");  
            dialog.setId("infoMessageDialog");
            dialog.setModal(true);           



          log.info(" panel height este "+panelHeight);

            ScrollPanel panelScroll = new ScrollPanel();
            panelScroll.setStyle("text-align: center;border:none;width:100%;heigth:"+panelHeight+"px;font-size:20px !important");
//            HtmlPanelGroup hpg=new HtmlPanelGroup();

            HtmlOutputLabel  hit = new HtmlOutputLabel();
            hit.setValue(text);

            hit.setStyle("text-align: center;vertical-align: middle;margin-top: 0px");
            hit.setId("inputhtmlmesajeInfo");
//            hpg.getChildren().add(hit);
            panelScroll.getChildren().add(hit);
            Panel panelButon = new Panel();
            panelButon.setStyle("border:none;text-align: center;height: 37px;margin-bottom: 2px");
            HtmlCommandButton button = new HtmlCommandButton();
            button.setValue("Log in");
            button.setStyle("text-align: center;width:40%;height: 33px;margin-bottom: 2px;font-size:20px !important");



            button.setActionExpression(createMethodExpression("#{login.redirectToLogin}"));;

            panelButon.getChildren().add(button);
            dialog.getChildren().add(panelScroll);
            dialog.getChildren().add(panelButon);
            panel.getChildren().add(dialog);


        RequestContext.getCurrentInstance().execute("PF('infoMessageDialog').show()");
        RequestContext.getCurrentInstance().update(panel.getClientId());

    }  
接下来,当我单击添加到该对话框中的命令按钮时,它将尝试使用

public void  redirectToLogin (){
        try {
            ((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()).sendRedirect("login.xhtml");
        } catch (IOException ex) {
           log.error("eroare la redirect ",ex);
        }
         }
一切正常,但在重定向之前会再次调用body-onload方法。问题是,为什么在添加动态按钮时,在重定向之前会再次调用onLoad,而在将其直接添加到html时(如下图所示) )不会被叫来吗? 我正在使用以下jsf版本

 compile ('com.sun.faces:jsf-api:2.2.8')   { transitive = false }
compile ('com.sun.faces:jsf-impl:2.2.8')   { transitive = false }

h:form
的位置很奇怪,非常奇怪(甚至可能是问题的部分原因)。请先更正它,相同的行为。我通过使用公共字符串redirectToLogin(){return“login.xhtml”;}更改redirectToLogin方法来解决问题
 compile ('com.sun.faces:jsf-api:2.2.8')   { transitive = false }
compile ('com.sun.faces:jsf-impl:2.2.8')   { transitive = false }