1
good afternoon.
I have a page called simulated.xhtml in which I receive some parameters (Filter) to make a query in the database according to the filter. Everything is already working, what I wanted was to take this query and display the questions on the same page, IE, Simulado.xhtml
Follow the source code:
Filter for consultation:
@Inject
private EntityManager manager;
public List<String> geraSimuladoPorFiltro(Long codigoCurso,
Integer complexidade, Integer numeroDeQuestoes) {
String query = "select pergunta from Questao WHERE curso_codigo = ?1 AND complexidade = ?2";
List<String> questoes = manager.createQuery(query, String.class)
.setParameter(1, codigoCurso).setParameter(2, complexidade)
.setMaxResults(numeroDeQuestoes).getResultList();
for (String q : questoes) {
System.out.println(q);
}
return questoes;
}
Gera Simulado Bean:
@Named
@ViewScoped
public class GerarSimuladoBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
SimuladoFiltroDAO simuladoFiltroDAO;
private Curso cursoSelecionado;
private Integer complexidadeSelecionada;
private Integer numeroDeQuestoesSimulado;
@Transactional
public void gerarSimulado() {
this.simuladoFiltroDAO.geraSimuladoPorFiltro(cursoSelecionado.getCodigo(),
this.complexidadeSelecionada, this.numeroDeQuestoesSimulado);
}
public Curso getCursoSelecionado() {
return cursoSelecionado;
}
public void setCursoSelecionado(Curso cursoSelecionado) {
this.cursoSelecionado = cursoSelecionado;
}
public Integer getComplexidadeSelecionada() {
return complexidadeSelecionada;
}
public void setComplexidadeSelecionada(Integer complexidadeSelecionada) {
this.complexidadeSelecionada = complexidadeSelecionada;
}
public Integer getNumeroDeQuestoesSimulado() {
return numeroDeQuestoesSimulado;
}
public void setNumeroDeQuestoesSimulado(Integer numeroDeQuestoesSimulado) {
this.numeroDeQuestoesSimulado = numeroDeQuestoesSimulado;
}
}
Pagina Simulado.xhtml
<ui:define name="titulo">Gerar Simulado</ui:define>
<ui:define name="corpo">
<h1>Filtro para gerar Simulado</h1>
<h:form id="frmCadastro">
<br></br>
<h:panelGrid columns="2">
<p:outputLabel value="Curso" for="curso" style="font-weight:bold" />
<p:selectOneMenu id="curso"
value="#{gerarSimuladoBean.cursoSelecionado}"
converter="cursoConverter" required="true"
requiredMessage="Preencha o curso">
<f:selectItem itemLabel="Selecione..." />
<f:attribute name="collectionType" value="java.util.ArrayList" />
<f:selectItems value="#{cadastroQuestaoBean.cursos}" var="curso"
itemLabel="#{curso.nome}" itemValue="#{curso}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="gridComplexidade" columns="2">
<p:outputLabel value="Complexidade da Questão" for="complexidade"
style="font-weight:bold" />
<p:selectOneMenu id="complexidade"
value="#{gerarSimuladoBean.complexidadeSelecionada}" required="true"
requiredMessage="Por favor, preencha a complexidade.">
<f:selectItem itemLabel="Selecione..." />
<f:selectItem itemLabel="1" itemValue="1" />
<f:selectItem itemLabel="2" itemValue="2" />
<f:selectItem itemLabel="3" itemValue="3" />
<f:selectItem itemLabel="4" itemValue="4" />
<f:selectItem itemLabel="5" itemValue="5" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="gridNumeroQuestoes" columns="2">
<p:outputLabel value="Número de questoes" for="numeroDeQuestoes"
style="font-weight:bold" />
<p:selectOneMenu id="numeroDeQuestoes"
value="#{gerarSimuladoBean.numeroDeQuestoesSimulado}" required="true"
requiredMessage="Por favor, preencha o numero de questoes.">
<f:selectItem itemLabel="Selecione..." />
<f:selectItem itemLabel="3" itemValue="3" />
<f:selectItem itemLabel="5" itemValue="5" />
<f:selectItem itemLabel="10" itemValue="10" />
<f:selectItem itemLabel="20" itemValue="20" />
<f:selectItem itemLabel="40" itemValue="40" />
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton value="Gerar Simulado" action="#{gerarSimuladoBean.gerarSimulado}"
icon="ui-icon-search" iconPos="right" update="frmCadastro">
</p:commandButton>
</h:form>
</ui:define>
I can already view the questions on the console, my goal is to display these questions on the same simulated page.xhtml
Thanks in advance.
Do you just want to show what’s already filtered? @Felipeportela
– Wellington Avelino
that’s right @Wellingtonavelino. Only that I wanted to display on the same screen simulated.xhtml because it is she who makes the filter. Is there any problem?
– Felipe Portela
Dude, I don’t see a problem, you can render this below your filter... You already have the objects to display?
– Wellington Avelino