0

I have a p:dataTable and the selected value is throwing null pointer when Im tring to get it,this situation is after put the datatable inside a modal p:dialog, but if remove the modal atribute works fine. PD:the modal p:dialog was behid the overlay like this question

Primefaces - AjaxStatus - Dialog is behind the overlay

the answer is not working for me, because Im using primefaces 5.1, so I have to use appendTo="@(body)"

I don´t know if that is important for my problem.

Resume: the null pointer exist if the p:dialog is modal.

Here is my code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<ui:composition template="/resources/sysged.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">


<ui:define name="vDoc">
    <h:form id="form">
        <p:panel header="Document">


            <h:panelGrid columns="4">
                <p:commandButton id="prev"
                    actionListener="#{DocumentController.priviousPage()}"
                    icon="ui-icon-circle-triangle-w" update="docImage next prev"
                    disabled="#{DocumentController.inicioLista}" />
                <p:commandButton id="next"
                    actionListener="#{DocumentController.nextPage()}"
                    icon="ui-icon-circle-triangle-e" update="docImage prev next"
                    disabled="#{DocumentController.finalLista}" />

                <p:commandButton id="anotacoes" value="Anotaçoes"
                    onclick="PF('dialogAnotacao').show();" />
                <p:button id="voltar" outcome="pesquisaDocumento.xhtml"
                    value="Voltar" />


            </h:panelGrid>

        </p:panel>



    </h:form>

    <h:form id="panotation">

        <p:dialog id="dialogAnotacao" closeOnEscape="true" header="Anotaçoes"
            widgetVar="dialogAnotacao" modal="true" resizable="false"
            appendTo="@(body)" draggable="true">


            <p:dataTable id="tanotation" var="anotation"
                value="#{DocumentController.arquivo.anotacaoList}"
                selectionMode="single"
                selection="#{DocumentController.selected}"
                rowKey="#{anotation.i}">



                <p:column headerText="Indice" style="text-align:left">
                    <h:outputText value="#{anotation.i}" />
                </p:column>
                <p:column headerText="text" style="text-align:left">
                    <h:outputText value="#{anotation.text}" />
                </p:column>

            </p:dataTable>

            <p:contextMenu for="tanotation">
                <p:menuitem value="do" update="tanotation"
                    icon="ui-icon-close" actionListener="#{DocumentController.doit}">
                </p:menuitem>
            </p:contextMenu>


        </p:dialog>

    </h:form>

</ui:define>
</ui:composition>

My method in the managedBean

public void doit() {

    System.out.println(selected);

}
Community
  • 1
  • 1
Juan Camilo Mejia
  • 952
  • 3
  • 14
  • 28

1 Answers1

0

You append your <p:dialog> to the body of the html page(see appendTo attribute), as a result it is not included in any <h:form>.

This could be a problem for your <p:dataTable>

Could you place your <h:form id="panotation"> inside of your <p:dialog> and not outside ?

Maxime
  • 168
  • 1
  • 9