2 Replies Latest reply on Dec 1, 2008 9:52 AM by nbelaevski

    a4j:loadScript and a4j:support problem

    oni_ffm

      hi,
      i want only highlight selected row in dataTable (i dont want to use scrollable dataTable or extended Datatable)
      i have read some topic. The simplest way i think that use java script file. (has someone another idea? i have tried with
      onRowClick="this.style.backgroundColor='#b3bffb'"
      but i can not reset not selected row, i want to use single select mode)

      so, my problem is that i can not load my java script file (i stored it in \WebContent\ )

      <ui:composition>
       <a4j:loadScript src="resource:///color.js"/>
       <h:form>
       <rich:dataTable value="#{dataTableBean.model}" var="model"
       binding="#{dataTableBean.table}">
      
       <a4j:support event="onRowClick" onsubmit="changeColor(this)"
       actionListener="#{dataTableBean.rowSelected}" />
      


      file color.js
      <script type="text/javascript">
      
       var oldRow;
       function changeColor(row) {
       if (oldRow != undefined) {
       oldRow.style.backgroundColor = '#ffffff';
       }
       row.style.backgroundColor = '#ebfbfb';
       oldRow = row;
       }
      </script>
      


      when i insert script direct in jsf file, it works fine. Maybe because of that i use a4j:loadScript and a4j:support at the same time? or have i forgot something?
      thanks

        • 1. Re: a4j:loadScript and a4j:support problem
          pbaker01

          Hi,

          If the script is not loaded in a jar you may want to just reference the file using the context relative path. The code below works for me:
          (be sure to include the leading slash)

           <ui:composition template="#{wabState.layout}">
          
           <ui:define name="header">
           <a4j:loadScript src="/js/Focus.js?version=5" />
           </ui:define>
          


          From the documentation:

          http://livedemo.exadel.com/richfaces-demo/richfaces/script.jsf;jsessionid=71C330B2644114E176A05258ED885E44?c=loadScript&tab=usage


          a4j:loadScript is similar to the standard script tag with src attribute, but it allows to load script from alternative sources like a jar file.

          src attribute defines the context relative path to the script. Instead of html script tag it's not required to have a prefix of your application. The leading slash in the path means the root of the web context.

          You can use "resource://" prefix to access the script file using RichFaces resource framework. For example, if your script file is located inside the jar file and has a full path there: /org/mycompany/assets/script/focus.js , you can point to it with:

          <a4j:loadScript src="resource:///org/mycompany/assets/script/focus.js" />


          • 2. Re: a4j:loadScript and a4j:support problem
            nbelaevski

            Hi,

            Try to remove resource:/// prefix