Target Unreachable, 'reply' returned null - SelectOneRadio

1

I can not get the value of my selectOneRadio , it comes as null :

<p:dataTable id="exibePerguntas" var="questao" paginator="true"
                rowsPerPageTemplate="2,3,5,10,12" paginatorPosition="bottom"
                value="#{responderSimuladoBean.simulado[0].questoes}">
                <p:column headerText="Perguntas">
                    <br></br>
                    <h:outputText escape="false" value="#{questao.pergunta}"  />

                <p:selectOneRadio id="resposta" style="width:25%"
                    value="#{responderSimuladoBean.resposta.respostaUsuario}">
                    <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>

                    <h:outputText value="#{responderSimuladoBean.resposta.resultado}" />
                </p:column>
            </p:dataTable>

            <p:commandButton process="@(#exibePerguntas)" id="enviarSimulado"
                value="Enviar Simulado" action="#{responderSimuladoBean.corrigirSimulado}"
                icon="ui-icon-search" iconPos="right" update=":frmCadastroSimulado">
            </p:commandButton>

The value that is coming null is value="#{responderSimuladoBean.resposta.respostaUsuario}">

The following is the error:

  

SERIOUS: javax.el.PropertyNotFoundException: /Simulado.xhtml @ 25,64   value="# {RespondSimpleBean.UserSet Response}": Target   Unreachable, 'response' returned null

More so far I could not identify the problem.

Follow my bean:

@Named
@ViewScoped
public class ResponderSimuladoBean implements Serializable {

    private static final long serialVersionUID = 3071538719985705117L;

    @Inject
    private SimuladoDAO simuladoDAO;

    @Inject
    private RespostaService respostaService;

    private Resposta resposta;
    private Usuario usuario = new Usuario();
    private List<Simulado> simulado;
    private List<Resposta> respostas = new ArrayList<Resposta>();

    @PostConstruct
    private void init() {

        simulado = this.simuladoDAO.buscaPorTodosSimulados();
    }

    @Transactional
    public void corrigirSimulado() throws Exception {
        respostas.clear();

        FacesContext fc = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
        Long codigoUsuario = (Long) session.getAttribute("identificaUsuario");
        usuario.setCodigo(codigoUsuario);

        for (Simulado s : simulado) {
            for (Questao q : s.getQuestoes()) {
                this.limpar();
                resposta.setUsuario(usuario);
                resposta.setQuestao(q);
                resposta.setRespostaCorreta(q.getRespostaPadraoPerguntaItem());
                respostas.add(resposta);
            }
        }

        this.respostaService.salvar(respostas);
    }

    private void limpar() {
        this.resposta = new Resposta();
    }

    public List<Simulado> getSimulado() {
        return simulado;
    }

    public List<Resposta> getRespostas() {
        return respostas;
    }

    public Resposta getResposta() {
        return resposta;
    }

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

}
    
asked by anonymous 30.10.2015 / 15:43

1 answer

1

The error Target Unreachable, 'resposta' returned null means that someone in the path returned null , so JSF can not retrieve the property value, ie, responderSimuladoBean is null (do not think likely) or responderSimuladoBean.resposta is (I think it's likely).

However, I believe you are using the wrong path in selectOneRadio because there is only one response in your Bean.

I think you should change it to something like:

@Named
@ViewScoped
public class ResponderSimuladoBean implements Serializable {

    private static final long serialVersionUID = 3071538719985705117L;

    @Inject
    private SimuladoDAO simuladoDAO;

    @Inject
    private RespostaService respostaService;

    // Removi um aqui
    private Usuario usuario = new Usuario();
    private List<Simulado> simulado;
    private List<Resposta> respostas = new ArrayList<Resposta>();

    @PostConstruct
    private void init() {
        simulado = this.simuladoDAO.buscaPorTodosSimulados();

        // Alterei para aqui
        for (Simulado s : simulado) {
            for (Questao q : s.getQuestoes()) {
                this.limpar();
                resposta.setUsuario(usuario);
                resposta.setQuestao(q);
                resposta.setRespostaCorreta(q.getRespostaPadraoPerguntaItem());
                respostas.add(resposta);
            }
        }
    }

    @Transactional
    public void corrigirSimulado() throws Exception {
        respostas.clear();

        FacesContext fc = FacesContext.getCurrentInstance();
        HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
        Long codigoUsuario = (Long) session.getAttribute("identificaUsuario");
        usuario.setCodigo(codigoUsuario);

        this.respostaService.salvar(respostas);
    }

    // código igual daqui para baixo

}

After that, you should change your JSF mapping to something like:

        <p:dataTable id="exibePerguntas" var="resposta" paginator="true"
            rowsPerPageTemplate="2,3,5,10,12" paginatorPosition="bottom"
            value="#{responderSimuladoBean.respostas}">
            <p:column headerText="Perguntas">
                <br></br>
                <h:outputText escape="false" value="#{questao.pergunta}"  />

            <p:selectOneRadio id="resposta" style="width:25%"
                value="#{resposta.respostaUsuario}">
                <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>

                <h:outputText value="#{resposta.resultado}" />
            </p:column>
        </p:dataTable>

        <p:commandButton process="@(#exibePerguntas)" id="enviarSimulado"
            value="Enviar Simulado" action="#{responderSimuladoBean.corrigirSimulado}"
            icon="ui-icon-search" iconPos="right" update=":frmCadastroSimulado">
        </p:commandButton>
    
30.10.2015 / 17:32