3 Replies Latest reply on Apr 2, 2010 9:25 AM by Zufar Muhamadeev

    Can`t add javascript

    Zufar Muhamadeev Newbie

      Hello.

      I am trying to add javascript to portlet GateIn 3.0.0-GA accroding to javascript configuration section in reference-guide.

      Here is portlet war structure:

       

      {quote}./WEB-INF/lib/commons-collections-3.2.1.jar
      ./WEB-INF/lib/portletbridge-api-2.0.0.CR1.jar
      ./WEB-INF/lib/portletbridge-impl-2.0.0.CR1.jar
      ./WEB-INF/web.xml
      ./WEB-INF/portlet.xml
      ./WEB-INF/faces-config.xml
      ./WEB-INF/classes/com/icl/cs/z22/jsf/Clock.class
      ./WEB-INF/classes/com/icl/cs/z22/jsf/ClockController.class
      ./WEB-INF/conf/script/groovy/JavascriptScript.groovy
      ./jsf/clock.jsp
      ./javascript/clock.js
      ./META-INF
      ./META-INF/MANIFEST.MF{quote}

       

      WEB-INF/conf/script/groovy/JavascriptScript.groovy contains single line:

       

      {code}JavascriptService.addJavascript("com.icl.cs.z22.clock", "/javascript/clock.js", ServletContext);{code}

       

      Here is ./javascript/clock.js file content:

       

      {code}function startClock(elementId, year, month, date, hours, minutes, seconds) {
          oDate = new Date(year, month, date, hours, minutes, seconds);
          window.setInterval(function () {
                clockStep(elementId, oDate);
              }
          ,1000);
      }

      function clockStep(elementId, theTime) {
          var nmins = theTime.getMinutes();
          var nhours = theTime.getHours();
          var nsec = theTime.getSeconds();
          var nmonth = theTime.getMonth();
          var ntoday = theTime.getDate();
          var nyear = theTime.getFullYear();
          var ssec = nsec;

          nmonth = nmonth + 1;       

          if (ntoday < 10) {
              ntoday = "0" + ntoday;
          }

          if (nmonth < 10) {
              nmonth = "0" + nmonth;
          }

          if (nhours < 10) {
              nhours = "0" + nhours;
          }
         
          if (nmins<10) {
              nmins = "0" + nmins;
          }

          if (nsec < 10) {
               ssec = "0" + ssec;
          }
         
          document.getElementById(elementId).value = ntoday + "." + nmonth + "." + nyear + " " + nhours + ":" + nmins + ":" + ssec;
         
          theTime.setSeconds(nsec + 1);
      }{code}

       

      And in .jsf/clock.jsp I invoke js function:

       

      {code}<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>


      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <f:view>
      <script>
          startClock("clock-area", ${clock.date.year + 1900},
                  ${clock.date.month},
                  ${clock.date.date},
                  ${clock.date.hours},
                  ${clock.date.minutes},
                  ${clock.date.seconds});
      </script>
      <div>
          <input id="clock-area">
      </div>
      <br/>
      </f:view>{code}

       

      After running this portlet clock doesn`t starts. And I don`t see clock.js in firebug and html source.

        • 1. Re: Can`t add javascript
          Zufar Muhamadeev Newbie

          I noticed that 01eXoResources.war doesn`t contains WEB-INF/conf/script/groovy/JavascriptScript.groovy file.

          But i found javascript declaration in ./01eXoResources.war/WEB-INF/gatein-resources.xml file:

           

          {code:xml}<javascript>

               <param>

                    <js-module>eXo</js-module>

                    <js-path>/javascript/eXo.js</js-path>

                    <js-priority>0</js-priority>

               </param>

          </javascript>{code}

           

          I tryied do declare same, but while deploying portlet war i see following stacktrace:

           

          {noformat}ERROR [GateInSkinConfigDeployer] An error occurs while registering '/WEB-INF/gatein-resources.xml' from the context 'null'
          java.lang.IllegalArgumentException: The context name cannot be null                                                                   
                  at org.exoplatform.container.definition.PortalContainerConfig.getPortalContainerNames(PortalContainerConfig.java:393)         
                  at org.exoplatform.container.PortalContainer.addInitTask(PortalContainer.java:380)                                            
                  at org.exoplatform.portal.resource.GateInSkinConfigDeployer.onEvent(GateInSkinConfigDeployer.java:99)                         
                  at org.gatein.wci.impl.DefaultServletContainer.safeFireEvent(DefaultServletContainer.java:147)                                
                  at org.gatein.wci.impl.DefaultServletContainer.fireEvent(DefaultServletContainer.java:166)                                    
                  at org.gatein.wci.impl.DefaultServletContainer.access$400(DefaultServletContainer.java:54)                                    
                  at org.gatein.wci.impl.DefaultServletContainer$RegistrationImpl.registerWebApp(DefaultServletContainer.java:250)              
                  at org.gatein.wci.tomcat.TC6ServletContainerContext.start(TC6ServletContainerContext.java:283)                                
                  at org.gatein.wci.tomcat.TC6ServletContainerContext.lifecycleEvent(TC6ServletContainerContext.java:141)                       
                  at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)                                    
                  at org.apache.catalina.core.StandardContext.start(StandardContext.java:4388)                                                  
                  at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:310)                   
                  at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:142)                           
                  at org.jboss.web.deployers.AbstractWarDeployment.start(AbstractWarDeployment.java:461)                                        
                  at org.jboss.web.deployers.WebModule.startModule(WebModule.java:118)                                                          
                  at org.jboss.web.deployers.WebModule.start(WebModule.java:97)                                                                 
                  at sun.reflect.GeneratedMethodAccessor298.invoke(Unknown Source)                                                              
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)                                      
                  at java.lang.reflect.Method.invoke(Method.java:597)                                                                           
                  at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)                                          
                  at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)                                                                
                  at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)                                                                  
                  at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)                                             
                  at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)                                                       
                  at org.jboss.system.microcontainer.ServiceProxy.invoke(ServiceProxy.java:206)                                                 
                  at $Proxy38.start(Unknown Source)                                                                                             
                  at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:42)                   
                  at org.jboss.system.microcontainer.StartStopLifecycleAction.installAction(StartStopLifecycleAction.java:37)
                  at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
                  at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
                  at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                  at org.jboss.system.microcontainer.ServiceControllerContext.install(ServiceControllerContext.java:286)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                  at org.jboss.system.ServiceController.doChange(ServiceController.java:688)
                  at org.jboss.system.ServiceController.start(ServiceController.java:460)
                  at org.jboss.system.deployers.ServiceDeployer.start(ServiceDeployer.java:163)
                  at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:99)
                  at org.jboss.system.deployers.ServiceDeployer.deploy(ServiceDeployer.java:46)
                  at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                  at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                  at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
                  at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                  at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
                  at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
                  at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                  at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                  at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
                  at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
                  at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
                  at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:362)
                  at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
                  at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
                  at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
                  at java.lang.Thread.run(Thread.java:619){noformat}
          • 2. Re: Can`t add javascript
            Trong Tran Master

            It has changed to declare javascript in gatein-resources.xml file instead of JavascriptScript.groovy. Unfortunately, it was not updated to the reference document.

             

            And it seems that your last exception is caused by you are missing the declaration of "<display-name>" in the web.xml file in your portlet war

            • 3. Re: Can`t add javascript
              Zufar Muhamadeev Newbie

              It works! Thanks)