1

I made my code like de PF Showcase, but it does't works... When i click my commandLink nothing happens. Anyone can help me? I already added Apache POI and iText.

enter image description here

        <h:form id="form">
            <p:commandButton value="Novo" icon="ui-icon-document"
                actionListener="#{controleBean.novoReservatorio()}" process="@this"
                update="dataTable reservatorio-dialog"
                oncomplete="PF('reservatorioDialog').show()" class="botaoDataTable">
                <p:resetInput target="reservatorio-dialog" />
            </p:commandButton>

            <p:commandButton icon="ui-icon-pencil" id="btnEditar" title="Editar"
                disabled="#{controleBean.reservatorio == null}"
                class="botaoDataTable" process="@this" update="dataTable :form"
                oncomplete="PF('reservatorioDialog').show()">
                <p:resetInput target="reservatorio-dialog" />
                <f:setPropertyActionListener target="#{controleBean.reservatorio}"
                    value="#{controleBean.reservatorioSelecao}" />
            </p:commandButton>

            <p:commandButton icon="ui-icon-trash" id="btnExcluir"
                title="Excluir" disabled="#{controleBean.reservatorio == null}"
                class="botaoDataTable" action="#{controleBean.excluirReservatorio}"
                process="@this" update="dataTable btnExcluir btnEditar" /> 

            <p:dataTable var="r" value="#{controleBean.reservatorios}"
                paginator="true" rows="30" id="dataTable"
                emptyMessage="Nenhum Reservatorio Cadastrado"
                paginatorPosition="bottom" 
                selection="#{controleBean.reservatorioSelecao}"
                selectionMode="single" rowKey="#{r.idReservatorio}"> 

                <p:ajax event="rowSelect"
                    update=":form:btnEditar :form:btnExcluir" />
                <p:ajax event="rowUnselect"
                    update=":form:btnEditar :form:btnExcluir" />

                <p:column headerText="Nome">
                    <h:outputText value="#{r.nomeReservatorio}" />
                </p:column>

                <p:column headerText="Capacidade (Lt)">
                    <h:outputText value="#{r.capacidadeReservatorio}" />
                </p:column>

                <p:column headerText="Tipo">
                    <h:outputText value="#{r.tipoReservatorio}" />
                </p:column>

                <p:column headerText="Observação">
                    <h:outputText value="#{r.obsReservatorio}" />
                </p:column>
            </p:dataTable>

            <p:commandLink>
                <p:graphicImage library="img" name="xlsx.png" width="32" title="Exportar para Excel"/>
                <p:dataExporter type="xls" target="dataTable" fileName="Relatorio" />
            </p:commandLink> 

            <h:commandLink>
                <p:graphicImage library="img" name="pdf.png" width="37" title="Exportar para PDF"/>
                <p:dataExporter type="pdf" target="dataTable" fileName="Relatorio"/>
            </h:commandLink>

            <p:commandButton value="Exportar para PDF" ajax="false">
                <p:dataExporter type="pdf" target=":form:dataTable" fileName="dataTable" />
            </p:commandButton>

            <p:dialog header="Reservatório" widgetVar="reservatorioDialog"
                id="reservatorio-dialog" resizable="false" modal="true"
                closeOnEscape="true">
                <p:messages style="font-size:70%;" />

                <p:panelGrid styleClass="semBorda">
                    <p:row>
                        <p:column>
                            <h:outputLabel for="nomeReservatorio" value="* Nome: "
                                class="componentePF label" />
                        </p:column>
                        <p:column>
                            <p:inputText id="nomeReservatorio" required="true"
                                value="#{controleBean.reservatorio.nomeReservatorio}"
                                requiredMessage="É necessário atribuir um nome à reservatorio"
                                class="componentePF text" />
                        </p:column>
                    </p:row>

                    <p:row>
                        <p:column>
                            <h:outputLabel for="capacidadeReservatorio"
                                value="* Capacidade (Lt): " class="componentePF label" />
                        </p:column>
                        <p:column>
                            <p:spinner id="capacidadeReservatorio" size="30"
                                value="#{controleBean.reservatorio.capacidadeReservatorio}"
                                min="0" stepFactor="1" required="true"
                                requiredMessage="É necessário atribuir uma capacidade à reservatorio"
                                class="componentePF text" />
                        </p:column>
                    </p:row>

                    <p:row>
                        <p:column>
                            <h:outputLabel for="tipoReservatorio"
                                value="* Tipo de Reservatório: " class="componentePF label" />
                        </p:column>
                        <p:column>
                            <p:selectOneMenu id="tipoReservatorio"  style="font-size:75% !important;"
                                value="#{controleBean.reservatorio.tipoReservatorio}"
                                class="componentePF text bold" required="true"
                                requiredMessage="É necessário atribuir um tipo ao reservatório">
                                <f:selectItem itemLabel="Escolha um Tipo para o Reservatório"
                                    noSelectionOption="true" />
                                <f:selectItem itemLabel="Escoamento" itemValue="Escoamento" />
                                <f:selectItem itemLabel="Reserva" itemValue="Reserva" />
                            </p:selectOneMenu>

                        </p:column>
                    </p:row>

                    <p:row>
                        <p:column>
                            <h:outputLabel for="obsReservatorio" value="Observação: "
                                class="componentePF label" />
                        </p:column>
                        <p:column>
                            <p:inputText id="obsReservatorio"
                                value="#{controleBean.reservatorio.obsReservatorio}"
                                class="componentePF text" />
                        </p:column>
                    </p:row>

                    <p:row>
                        <p:column colspan="2">
                            <p:commandButton value="Cadastrar" icon="ui-icon-disk"
                                action="#{controleBean.cadastrarReservatorio}"
                                id="cadastrarReservatorio" ajax="false"
                                class="componentePF button" />
                        </p:column>
                    </p:row>
                </p:panelGrid>
            </p:dialog>
        </h:form>
Hugo Deiró
  • 224
  • 2
  • 13
  • But what **does** happen. The way you describe it is like an end-user and I assume you are a very skilled developer, so check the browser developer tools network tab etc...Try breakpoints in your code and more – Kukeltje Nov 18 '15 at 15:10
  • That's the question. Absolutely nothing happens. I click and i got no errors, no responses, nothing. – Hugo Deiró Nov 18 '15 at 15:13
  • can u post whole form, please? if u use firebug or other debugging tools, enable javascript debug and click on the commandLink and look what happens in console? – Mahendran Ayyarsamy Kandiar Nov 18 '15 at 15:32
  • @MahendranAyyarsamyKandiar: next time ask for an [mcve], not the whole form… waaay to much noise now in the code – Kukeltje Nov 18 '15 at 16:24
  • @Kukeltje okay. I was just wondering if there were issues in the form that returned false on his onclick. I will bookmark this link. – Mahendran Ayyarsamy Kandiar Nov 18 '15 at 16:27
  • @MahendranAyyarsamyKandiar, both alerts come in. I didn't see any errors. – Hugo Deiró Nov 18 '15 at 16:35
  • @HugoDeiró Primefaces.monitorDownload (http://blog.primefaces.org/?p=1616) uses http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in-the-browser/ like solution. So if the stop alert came in the "fileDownloadToken" cookie has been removed successfully after file download. Check the folder where browser downloads. if the file is not there, i am not sure what is happening and am giving up. Good luck! – Mahendran Ayyarsamy Kandiar Nov 18 '15 at 16:50
  • Possible duplicate of [Export to Excel JSF and PrimeFaces](https://stackoverflow.com/questions/7822758/export-to-excel-jsf-and-primefaces) – Kukeltje Oct 21 '17 at 13:42

1 Answers1

1

The first <p:commandLink> doesn't work be cause it sends an ajax request. Just add ajax="false" to solve the problem.

See https://stackoverflow.com/a/7740280/1980659 for the root cause explanation.

With what you provided the two other buttons should work.

Community
  • 1
  • 1
ForguesR
  • 3,558
  • 1
  • 17
  • 39