1 Reply Latest reply on Jun 29, 2010 8:41 PM by luizsync

    JavaScript + JSF: Problem

    luizsync

      Good day!





      I've got some problems with JavaScritp and JSF.
      Please, could someone help-me?


      I'm trying to integrate this javaScript in my JSF source:



      // --------------------- validacao.js ---------------------
      public boolean teste(String f)
      {
              if (f==''){
                      alert('vazio')
              }else{ 
                      alert('cheio  ' + f)
              }
      } 
      




      This is my JSF source:
      //---------------------------------------------------------------



      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              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:rich="http://richfaces.org/rich" template="layout/template.xhtml">
              
              <ui:define name="head">
                      <script  language="javascript" src="javascripts/validacao.js" ></script>
              </ui:define>
              
              <ui:define name="body">   
                      <h1>Welcome to Seam!</h1>
                      <rich:panel>
                              <h:panelGrid columns="1">
                                      <s:div styleClass="info">
                                              <h:form id="userForm">
                                                      teste: <h:inputText id="numero" value="" />
                                                      <h:commandButton 
                                                              id="lnkDeleteUser" 
                                                              value="teste"
                                                              onclick="
                                                                      var numero = document.getElementById('userForm:numero').value  ;
                                                                      teste(numero);
                                                                      " 
                                                                      action="/javascript2.xhtml" />
                                              </h:form>
                                      </s:div>
                              </h:panelGrid>
                      </rich:panel>
              </ui:define>
      </ui:composition>
      //---------------------------------------------------------------
      




      there are those tags where I call my validacao.js:


              <ui:define name="head">
                      <script  language="javascript" src="javascripts/validacao.js" ></script>
              </ui:define>
      
      But the onclick doesn't work:
      
                      <h:form id="userForm">
                              teste: <h:inputText id="numero" value="" />
                              <h:commandButton 
                              id="lnkDeleteUser" 
                              value="teste"
                              onclick="
                                      var numero = document.getElementById('userForm:numero').value  ;
                                      teste(numero);
                                      " 
                                      action="/javascript2.xhtml" />
                      </h:form>
      
      


      If I put this source code it works nice:


              <h:form id="userForm">
                      teste: <h:inputText id="numero" value="" />
                      <h:commandButton 
                      id="lnkDeleteUser" 
                      value="teste"
                      onclick="
                      if (document.getElementById('userForm:numero').value == '') alert('Olá!') ;
                      else alert('tchau!');
                      "
                      action="/javascript.xhtml" />
              </h:form>
      
      


      Where is my mistake?


        • 1. Re: JavaScript + JSF: Problem
          luizsync

          I found my mistake. Sorry about this topc. It was my mistake:


          // --------------------- validacao.js ---------------------
          function teste(String f)
          {
                  if (f==''){
                          alert('vazio')
                  }else{ 
                          alert('cheio  ' + f)
                  }
          }