Erro JavaScript

8 respostas
Chuvinha

Galera, estou desenvolvendo uma aplicação com JSF 1.2 e JQuery. Adicionei uma function na minha página xhtml e está dando esse erro.

com.sun.facelets.FaceletException: Error Parsing /pages/manutencao/email/home.xhtml: Error Traced[line: 16] The entity name must immediately follow the '&' in the entity reference.

Minha página está assim:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition 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">

	<f:view>

		<script type="text/javascript">
			function formatar(src, mask , e ){
				
		        var tecla = ( window.event ) ? e.keyCode : e.which;/*pega qual tecla foi pressionada*/
		        
		        if((tecla > 47 && tecla < 58)) return true;  
		        else{  
		            if ((tecla != 0)&&(tecla !=8)) return false;  
		            else return true;   
		        }
		
		    }
		</script>
	</f:view>

</ui:composition>

Alguém poderia me ajudar?

8 Respostas

mauricioadl

tira o JS de dentro do f:view e coloca dentro de h:head pra ver se resolve.

rafaduka

como está chamando?

formatar(src, mask , e )
Chuvinha

Mauricio, alterei o código como vc sugeriu e agora aparece outro erro:

com.sun.facelets.tag.TagException: /pages/manutencao/email/home.xhtml @9,10 <h:head> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: head

Meu código ficou assim:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	
	<h:head>
		<script type="text/javascript">
			function formatar(src, mask , e ){
				
		        var tecla = ( window.event ) ? e.keyCode : e.which;/*pega qual tecla foi pressionada*/
		        
		        if((tecla > 47 && tecla < 58)) return true;  
		        else{  
		            if ((tecla != 0)&&(tecla !=8)) return false;  
		            else return true;   
		        }
		
		    }
		</script>
	</h:head>

	<f:view>

		
	</f:view>

</ui:composition>

Rafaduka, estou chamando essa function assim:

<h:inputText id="id_first_hour1" value="#{email.emailTO.primeiroHorario}" maxlength="8" onkeypress="formatar( this , '00:00:00' , event )"/>
rafaduka

tente assim:

<h:outputScript library="js" name="common.js" target="head" />

fonte

Chuvinha

Amigo, não está dando erro pra chamar a function. Está dando pra carregar a página.

rafaduka

Ele não está conseguindo fazer o parsing da home.xhtml por causa do operador &.
tente substituir o operador por: &+amp; sem o (+)

aconselho utilizar o encoding para:

<?xml version="1.0" encoding="ISO-8859-1" ?>
Chuvinha

Putz, eu acrescentei o & e agora aparece outro erro:

com.sun.facelets.FaceletException: Error Parsing /pages/manutencao/email/alterarTipoEmail.xhtml: Error Traced[line: 10] The content of elements must consist of well-formed character data or markup.
T
Chuvinha:
Mauricio, alterei o código como vc sugeriu e agora aparece outro erro:
com.sun.facelets.tag.TagException: /pages/manutencao/email/home.xhtml @9,10 <h:head> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: head

Meu código ficou assim:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	
	<h:head>
		<script type="text/javascript">
			function formatar(src, mask , e ){
				
		        var tecla = ( window.event ) ? e.keyCode : e.which;/*pega qual tecla foi pressionada*/
		        
		        if((tecla > 47 && tecla < 58)) return true;  
		        else{  
		            if ((tecla != 0)&&(tecla !=8)) return false;  
		            else return true;   
		        }
		
		    }
		</script>
	</h:head>

	<f:view>

		
	</f:view>

</ui:composition>

Rafaduka, estou chamando essa function assim:

<h:inputText id="id_first_hour1" value="#{email.emailTO.primeiroHorario}" maxlength="8" onkeypress="formatar( this , '00:00:00' , event )"/>

Caso não tenha conseguido corrigir o problema aí vai a solução:
Obs: Não precisa mudar o encoding da página, pode deixá-la como UTF-8

<script type="text/javascript">
<!--
seu código javascript aqui
//-->
</script>

ou

<script type="text/javascript">
//<![CDATA[
seu código javascript aqui
//]]>
</script>
Criado 3 de abril de 2012
Ultima resposta 23 de jul. de 2012
Respostas 8
Participantes 4