[RESOLVIDO]Problema com JSF

2 respostas
C
Estou levando erro 500 ao tentar executar um primeiro "projeto" com JSF
11/04/2012 13:58:06 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/k19-loteria] threw exception [Error Parsing /formulario.xhtml: Error Traced[line: 1] Content is not allowed in prolog.] with root cause
javax.faces.view.facelets.FaceletException: Error Parsing /formulario.xhtml: Error Traced[line: 1] Content is not allowed in prolog.

Erro no Console

O Erro acontece ao acessar a seguinte pagina...

Logo abaixo segue o BEAN


<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html">
<h:head>
	<title>Gerador de Apostas</title>
</h:head>
<h:body>
	<h:form>
		<h:panelGrid>
			<h:outputLabel value="Quantidade Total de Numeros" />
			<h:inputText value="#{geradorDeApostasBean.quantidadeDeNumeros}" />

			<h:outputLabel value="Quantidade de números por aposta:" />
			<h:inputText value="#{geradorDeApostasBean.tamanhoDaAposta}" />

			<h:outputLabel value="Quantidade de apostas:" />
			<h:inputText value="#{geradorDeApostasBean.quantidadeDeApostas}" />
			<h:commandButton action="#{geradorDeApostasBean.geraApostas}" value="Gerar"/>
		</h:panelGrid>

	</h:form>

</h:body>
</html>
package managedbeans;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class GeradorDeApostasBean {
	private int quantidadeDeNumeros;

	private int tamanhoDaAposta;

	private int quantidadeDeApostas;

	private List<List<Integer>> apostas;

	public String geraAposta() {
		ArrayList<Integer> numeros = new ArrayList<Integer>();

		for (int j = 0; j < this.quantidadeDeNumeros; j++) {
			numeros.add(j);

		}
		// Cria uma sublista da lista de numeros
		List<Integer> subList = numeros.subList(0, this.tamanhoDaAposta);

		// Lista de apostas vazia
		this.apostas = new ArrayList<List<Integer>>();

		for (int i = 0; i < this.quantidadeDeApostas; i++) {
			Collections.shuffle(numeros);
			List<Integer> aposta = new ArrayList<Integer>(subList);
			this.apostas.add(aposta);
		}
		
		return "lista-de-apostas";
	}

	// Getter e setters

	public int getQuantidadeDeNumeros() {
		return quantidadeDeNumeros;
	}

	public void setQuantidadeDeNumeros(int quantidadeDeNumeros) {
		this.quantidadeDeNumeros = quantidadeDeNumeros;
	}

	public int getTamanhoDaAposta() {
		return tamanhoDaAposta;
	}

	public void setTamanhoDaAposta(int tamanhoDaAposta) {
		this.tamanhoDaAposta = tamanhoDaAposta;
	}

	public int getQuantidadeDeApostas() {
		return quantidadeDeApostas;
	}

	public void setQuantidadeDeApostas(int quantidadeDeApostas) {
		this.quantidadeDeApostas = quantidadeDeApostas;
	}

	public List<List<Integer>> getApostas() {
		return apostas;
	}

	public void setApostas(List<List<Integer>> apostas) {
		this.apostas = apostas;
	}

}

2 Respostas

T

O seu xhtml está errado:
1 - Primeiro pois tem um símbolo estranho na primeira linha
2 - tem que ter o cabeçalho padrão

abaixo tem o código corrigido

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
    xmlns:h="http://java.sun.com/jsf/html">  
<h:head>  
    <title>Gerador de Apostas</title>  
</h:head>  
<h:body>  
    <h:form>  
        <h:panelGrid>  
            <h:outputLabel value="Quantidade Total de Numeros" />  
            <h:inputText value="#{geradorDeApostasBean.quantidadeDeNumeros}" />  
  
            <h:outputLabel value="Quantidade de números por aposta:" />  
            <h:inputText value="#{geradorDeApostasBean.tamanhoDaAposta}" />  
  
            <h:outputLabel value="Quantidade de apostas:" />  
            <h:inputText value="#{geradorDeApostasBean.quantidadeDeApostas}" />  
            <h:commandButton action="#{geradorDeApostasBean.geraApostas}" value="Gerar"/>  
        </h:panelGrid>  
  
    </h:form>  
  
</h:body>  
</html>
C

Resolvido, entao o DOCTYPE eu tinha colocado , mas faltou a primeira linha la mesmo…

Valeu cara.

Criado 11 de abril de 2012
Ultima resposta 11 de abr. de 2012
Respostas 2
Participantes 2