JSF page displaying Object reference value

Asked

Viewed 267 times

3

good night.

I have a JSF page called simulated.xhtml on which implement a filter to generate the simulated and I’m also trying to display results from the database that have already been filtered on this page, but as a result I get these results:

[com.sisEnade.tcc.modelo.Questao@20, com.sisEnade.tcc.modelo.Questao@21, com.sisEnade.tcc.modelo.Questao@22]

I tried to implement in a datatable more whenever I click on generate Simulated I get a notfound, it’s like the datatable needs to reload right after clicking on the button. You can help me with that detail too?

I’m trying to exhibit the following way to test:

Page JSF:

    <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>
            <br></br>
            <br></br>
            <br></br>
            <br></br>
            <p:panelGrid id="teste">
                <h:outputText value="#{gerarSimuladoBean.questoes}">
                </h:outputText>
            </p:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>

Snippet where you are displaying object addresses:

<p:panelGrid id="teste">
                    <h:outputText value="#{gerarSimuladoBean.questoes}">
                    </h:outputText>
</p:panelGrid>

1 answer

6


Such value appears because you are having print the object from the list here:

<h:outputText value="#{gerarSimuladoBean.questoes}">

If the value passed to the tag <h:outputText> is not a String, the method toString() of the object will be called to obtain the textual representation of it.

The problem would not occur with the component <dataTable> because it would manage to display each item in the list properly, but for it to work you really need to instruct the table to update when clicking the button.

The update should already occur because you used the attribute update on the button.

I did not quite understand what you meant by "notfound". If the button method really exists, no such error should occur. Be careful if you are redirecting to a non-existent location, but this should not occur, because the updating of the components in Primefaces is done via Ajax.

This is all the help I can give with the information available.

  • Thanks friend, solved perfectly. However, I am with another problem. I posted further below as an answer, please can help me?

  • 1

    @Felipeportela I don’t understand what you mean by "datatable console". If you are displaying the texts one after the other on a web page, they will not respect line breaks in the page code. To break lines in HTML you can use tags <br/>, <p> or, better still in that context, list not listed with <ul> and <li>.

Browser other questions tagged

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