Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: EE-2.0.0.GA
    • Fix Version/s: EE-3.0.0.BETA, 3.0.1
    • Component/s: Framework
    • Labels:
      None
    • Environment:
      Tomcat 7, Chrome17, IE9, FF10

      Description

      We have a simple page like this:

      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:icecore="http://www.icefaces.org/icefaces/core"
            xmlns:ace="http://www.icefaces.org/icefaces/components"
            xmlns:ice="http://www.icesoft.com/icefaces/component">
              <h:head>
                  <title>Javascript test</title>
              </h:head>
              <h:body styleClass="ice-skin-rime">
                  <h:panelGrid columns="1">
                      <h:outputText value="#{testJavascriptBean.test}"/>
                  </h:panelGrid>

                  <h:form id="form">
                      <h:panelGrid columns="1">
                          <h:commandButton value="Alert" actionListener="#{testJavascriptBean.addScript}"/>
                      </h:panelGrid>
                  </h:form>
              </h:body>
      </html>
      >>>>>>>>>>>>>>>>>>>>>>>
      And a simple Bean like this:

      @ManagedBean
      @RequestScoped
      public class TestJavascriptBean {
          private String test = "Test";

          public TestJavascriptBean() {
              someLogic();
          }

          public void addScript(ActionEvent event)
          {
              someLogic();
          }
         
          private void someLogic()
          {
              FacesContext context = FacesContext.getCurrentInstance();
              if(context != null)
              {
                  JavaScriptRunner.runScript(FacesContext.getCurrentInstance(), "alert('test');");
                  test = "alert added";
              }
              else
              {
                  test = "alert not added";
              }
          }

          public String getTest()
          {
              return test;
          }

          public void setTest(String test)
          {
              this.test = test;
          }
      >>>>>>>>>>>>>>>>>>>>>
      During initial page load JSF jumps from RestoreView to Render Response right away. While in Render Response phase the TestJavascriptBean is constructed and someLogic() method is executed. Inside this method we have a call to JavaScriptRunner.runScript(FacesContext.getCurrentInstance(), "alert('test');"). This call in theory should create a popup alert window once the page is loaded in the browser, but it never happens. I can see that someLogic() is executed since test variable change it's value from "test" to "alert added".

      I also tried to put someLogic() method into preRenderView listener as well as in getTest() method with no luck in each case.
      Once page is loaded and let's say a commandButton is clicked JavaScriptRunner.runScript work just fine and I can see the alert window which is displayed twice. First time because call to the JavaScriptRunner.runScript is done via TestJavascriptBean constructor, second because of the addScript(ActionEvent event) execution.

        Activity

        Hide
        Mircea Toma added a comment -

        Added JavaScriptRunnerSetup system event listener back into faces-config.xml so that the scripts are inserted in the page during page load.

        Show
        Mircea Toma added a comment - Added JavaScriptRunnerSetup system event listener back into faces-config.xml so that the scripts are inserted in the page during page load.
        Hide
        Evgheni Sadovoi added a comment - - edited

        For some reason the JavaScriptRunnerSetup system event listener is not registered in the faces-config.xml anymore. This class is responsible for rendering the JS code on page load.

        Show
        Evgheni Sadovoi added a comment - - edited For some reason the JavaScriptRunnerSetup system event listener is not registered in the faces-config.xml anymore. This class is responsible for rendering the JS code on page load.

          People

          • Assignee:
            Mircea Toma
            Reporter:
            Evgheni Sadovoi
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: