Olá pessoal, estou aprendendo JSF e não estou conseguindo fazer um exercício simples de uma apostila do K19, parece que não estou conseguindo setar atributos no meu managedBean, seguem os códigos:
GeradorDeApostasBeanpackage managedbeans;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.faces.bean.ManagedBean;
@ManagedBean //(name = "GeradorDeApostasBean")
public class GeradorDeApostasBean {
private int quantidadeNumeros;
private int tamanhoDaAposta;
private int quantidadeDeApostas;
private List<List<Integer>> apostas;
public void setQuantidadeNumeros(int quantidadeNumeros){
this.quantidadeNumeros = quantidadeNumeros;
}
public String geraApostas() {
// prepara uma lista com todos os numeros
ArrayList<Integer> numeros = new ArrayList<Integer>();
for (int j=1; j <= this.quantidadeNumeros; j++) {
numeros.add(j);
}
// cria uma sublista da lista de numeros
List<Integer> subList = numeros.subList(0, this.tamanhoDaAposta);
// lista de apostas vazias
this.apostas = new ArrayList<List<Integer>>();
// gera as apostas
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";
}
}
<?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 números:"/>
<h:inputText value="#{GeradorDeApostasBean.quantidadeNumeros}"/>
<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>
<?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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Gerador de Apostas</title>
</h:head>
<h:body>
<ui:repeat var="aposta" value="#{GeradorDeApostasBean.apostas}" varStatus="status">
<h:outputText value="Aposta #{status.index + 1}: "/>
<h:outputText value="#{aposta}" />
<br/>
</ui:repeat>
</h:body>
</html>
/formulario.xhtml @12,69 value="#{GeradorDeApostasBean.quantidadeNumeros}": Target Unreachable, identifier 'GeradorDeApostasBean' resolved to null
Eu não entendi bem a utilização, tipo eu estou tentando setar o atributo direto: GeradorDeApostasBean.quantidadeNumeros, mas o atributo é private, ele chama o setter e instância um objeto automaticamente?