Selectoneradio sending only one value

Asked

Viewed 132 times

0

I am concluding a simulation system for my course completion work. However, I have a problem that I have not yet been able to solve.

I perform a filter to select the questions for the user to answer, and set those questions that were found by the filter within a List. However, when the student answers these questions selectOneRadio only takes the last value and not all the answers values to make the comparison.

Can someone help me?

Follows the related codes:

Filter:

    public class SimuladoFiltroDAO implements Serializable {

        private static final long serialVersionUID = 1L;

        @Inject
        private EntityManager manager;

        @SuppressWarnings("unchecked")
        public List<Questao> geraSimuladoPorFiltro(Long codigoCurso,
                Integer complexidade, Integer numeroDeQuestoes) {
            String query = "SELECT NEW com.sisEnade.tcc.modelo.Questao(q.codigo, q.pergunta, "
                    + "q.respostaPadraoPerguntaItem) FROM Questao q "
                    + "WHERE CURSO = ?1 AND complexidade = ?2";
            List<Questao> questoes = manager.createQuery(query)
                    .setParameter(1, codigoCurso).setParameter(2, complexidade)
                    .setMaxResults(numeroDeQuestoes).getResultList();
            for (Questao questao : questoes) {
                System.out.println(questao.getCodigo());
                System.out.println(questao.getPergunta());
                System.out.println(questao.getRespostaPadraoPerguntaItem());
            }
            return questoes;
        }

Simulado Bean: 

@Named
@ViewScoped
public class GerarSimuladoBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    SimuladoFiltroDAO simuladoFiltroDAO;

    @Inject
    private RespostaService respostaService;

    private Curso cursoSelecionado;
    private Integer complexidadeSelecionada;
    private Integer numeroDeQuestoesSimulado;
    private Resposta resposta = new Resposta();

    private List<Questao> questoes;

    @Transactional
    public void gerarSimulado() {
        this.questoes = simuladoFiltroDAO.geraSimuladoPorFiltro(
                cursoSelecionado.getCodigo(), this.complexidadeSelecionada,
                this.numeroDeQuestoesSimulado);
        this.resposta.setQuestao(questoes);
    }

    @Transactional
    public void enviar() {
        this.respostaService.salvar(resposta);
        FacesUtil.addSuccessMessage("Resposta salva com sucesso");
    }

    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;
    }

    public List<Questao> getQuestoes() {
        return questoes;
    }

    public void setQuestoes(List<Questao> questoes) {
        this.questoes = questoes;
    }

    public Resposta getResposta() {
        return resposta;
    }

    public void setResposta(Resposta resposta) {
        this.resposta = resposta;
    }

}   

Here is an image of my most detailed problem, I get a list of questions and answer two questions only it only sends one answer and not both.

Unica resposta SelectOneRadio

XHTML From the stretch involved:

<p:dataTable id="exibePerguntas" var="questao"
                value="#{gerarSimuladoBean.questoes}" >
                <p:column headerText="Perguntas">
                    <br></br>
                    <p:outputLabel value="#{questao.pergunta}" />
                    <p:selectOneRadio id="resposta" style="width:25%" value="#{gerarSimuladoBean.resposta.respostaItem}">
                        <f:selectItem itemLabel="A" itemValue="A" />
                        <f:selectItem itemLabel="B" itemValue="B" />
                        <f:selectItem itemLabel="C" itemValue="C" />
                        <f:selectItem itemLabel="D" itemValue="D" />
                    </p:selectOneRadio>
                </p:column>
            </p:dataTable>
            <p:commandButton id="enviarSimulado" value="Enviar Simulado"
                    action="#{gerarSimuladoBean.enviar}" icon="ui-icon-search"
                    iconPos="right" update=":frmCadastroSimulado">
                </p:commandButton>

Valeus!

1 answer

1


You can try to do how are you here.

Create a Question and Answer Map... instead of assigning the variable resposta.respostaItem, Voce creates a Map<Pergunta, Resposta> selectedOptions . That’s where the assignment goes:

<p:selectOneRadio value="#{gerarSimuladoBean.selectedOptions[question]}">
  • Buddy, I don’t think you’re gonna solve my question yet. What I would have to do more or less is take each answer and assign it to the exact line of the question that was displayed. What is being displayed to the user is a List of questions, but the answer is only one for each question, what I need to do more or less is to indicate somehow in my datatable that that answer is to that line on my List. Can you help me?

  • see if it helps now

  • That’s right Pedro, thanks bro! Solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.