SelectOneRadio sending only one value

0

I am completing a simulation system for my course completion work. However, I have a problem that I still can not solve.

I do a filter to select the questions for the user to answer, and I play those questions that were found by the filter within a List. However, at the time of the student answering these questions the selectOneRadio only takes the last value and not all the values of the answer to make the comparison.

Can anyone help me?

Follow 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 more detailed problem, I get a list of questions and I answer two questions, but it only sends one answer, not both.

XHTMLOfthestretchinvolved:

<p:dataTableid="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!

    
asked by anonymous 17.10.2015 / 16:26

1 answer

1

You can try how are you .

Create a Question and Answer Map ... there instead of assigning the variable resposta.respostaItem , you create a Map<Pergunta, Resposta> selectedOptions . Then the assignment looks like this:

<p:selectOneRadio value="#{gerarSimuladoBean.selectedOptions[question]}">
    
19.10.2015 / 14:41