簡體   English   中英

我的命令按鈕不起作用,JSF + primefaces?

[英]my commandbutton doesnt work, JSF + primefaces?

從DB(postgre)中挑選數據,

這個頁面首先列出列表中的數據然后我有一個commandlink“modificar”,它攜帶來自對話框中點擊的元素的數據,但我不知道為什么這個對話框中的命令按鈕不會調用方法“DAOEventos.modificarEvento”...最后,我有一個按鈕,從對話框向數據庫注冊數據,這是可行的

我唯一的問題是對話來自commandlink!

我做了一個調試,問題是“p:calendar”,如果我踢它,方法被調用,但我需要從日歷中獲取該值!

<h:body>
    <h:form id="form">            
        <p:dataTable style="width:100%" value="#{DAOEventos.listaEventos()}" var="even" >

            <f:facet name="header">Listado de Eventos</f:facet>
            <p:column filterBy="#{even.descripcion}" filterMatchMode="contains">
                <f:facet name="header">
                    <h:outputLabel value="Evento"/>
                </f:facet>
                <h:outputText value="#{even.descripcion}"></h:outputText>

            </p:column>
            <p:column filterBy="#{even.fec}" filterMatchMode="contains">
                <f:facet name="header">

                    <h:outputLabel value="Fecha"/>
                </f:facet>
                <h:outputText value="#{even.fec}"></h:outputText>

            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputLabel value="Modificar"/>
                </f:facet>
                <p:commandLink value="Modificar" oncomplete="dlg2.show();" 
                               update="modalDialog2" action="#{beanEventos.traerDatos()}" style="color: black">
                    <f:setPropertyActionListener target="#{beanEventos.codEvento}" value="#{even.codEvento}" />
                    <f:setPropertyActionListener target="#{beanEventos.codSec}" value="#{even.codSec}" />
                </p:commandLink>

                <p:dialog id="modalDialog2" header="Modificar Eventos" widgetVar="dlg2" dynamic="true" resizable="false">  
                    <h:form>
                        <table>
                            <tr>
                                <td>
                                    <h:outputLabel value="Nombre Evento"/>
                                    <h:inputText id="nombre"  value="#{beanEventos.nombre}"/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <h:outputLabel value="Descripcion Evento"/>
                                    <h:inputText id="desc"  value="#{beanEventos.descripcion}"/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <h:outputLabel value="Fecha Evento"/>
                                    <p:calendar value="#{beanEventos.fec}" 
                                                showButtonPanel="true"/>                      
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <h:selectBooleanCheckbox value="#{beanEventos.vigencia}"/> 
                                    <h:outputText value="Vigencia" style="font-weight:bold"/>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <h:commandButton value="Modificar" action="#{DAOEventos.modificarEvento()}" />
                                </td>
                            </tr>
                        </table>
                    </h:form>
                </p:dialog>
            </p:column>
        </p:dataTable> 

        <p/>
        <p:commandButton id="showDialogButton"  value="Agregar" oncomplete="dlg.show()" /> 

        <p:dialog header="Enter FirstName" widgetVar="dlg" resizable="false" id="dialogo"  >  
            <h:form>

                <table>
                    <tr>
                        <td>
                            <h:outputLabel value="Nombre Evento "/>
                            <h:inputText id="nombre"  value="#{beanEventos.nombre}"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel value="Descripcion Evento "/>
                            <h:inputText id="desc"  value="#{beanEventos.descripcion}"/>
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <h:outputLabel value="Fecha de Evento"/>
                            <p:calendar value="#{beanEventos.fec}" id="cal" showButtonPanel="true"/>  
                        </td>
                    </tr>

                    <tr>
                        <td>
                            <h:commandButton value="Registrar Evento"
                                             action="#{DAOEventos.insertarEvento()}"/>
                        </td>
                    </tr>
                </table>
            </h:form>
        </p:dialog>  

    </h:form>  
</h:body>

您正在將一個HTML form嵌套在另一個HTML form ,這不是HTML中的有效概念。 即使你在JSF終極渲染組件中這樣做也只是HTML。所以,從你的代碼中刪除<h:form id="form">或者嘗試將所有上述代碼保存在單個表單中。

檢查這里: 如何在JSF頁面中使用<h:form>? 單一形式? 多種形式? 嵌套表格?

正如SrinivasR所說,你不應該(雖然這可能工作正常)窩形式。 但我認為這里的問題在於您定義的地方:

<p:dialog id="modalDialog2">...</p:dialog>

你應該把它放在數據表之外。

<h:body>
<h:form id="form">            
    <p:dataTable style="width:100%" value="#{DAOEventos.listaEventos()}" var="even" >

        <f:facet name="header">Listado de Eventos</f:facet>
        <p:column filterBy="#{even.descripcion}" filterMatchMode="contains">
            <f:facet name="header">
                <h:outputLabel value="Evento"/>
            </f:facet>
            <h:outputText value="#{even.descripcion}"></h:outputText>

        </p:column>
        <p:column filterBy="#{even.fec}" filterMatchMode="contains">
            <f:facet name="header">

                <h:outputLabel value="Fecha"/>
            </f:facet>
            <h:outputText value="#{even.fec}"></h:outputText>

        </p:column>
        <p:column>
            <f:facet name="header">
                <h:outputLabel value="Modificar"/>
            </f:facet>
            <p:commandLink value="Modificar" oncomplete="dlg2.show();" 
                           update=":padding" actionListener="#{beanEventos.traerDatos()}" style="color: black">
                <f:setPropertyActionListener target="#{beanEventos.codEvento}" value="#{even.codEvento}" />
                <f:setPropertyActionListener target="#{beanEventos.codSec}" value="#{even.codSec}" />
            </p:commandLink>


        </p:column>
    </p:dataTable> 
</h:form> 
    <p/>
    <h:panelGroup id="padding" layout="block">
        <p:dialog id="modalDialog2" header="Modificar Eventos" widgetVar="dlg2" dynamic="true" resizable="false">  
            <h:form id="form2">     
                <table>
                    <tr>
                        <td>
                            <h:outputLabel value="Nombre Evento"/>
                            <h:inputText id="nombre"  value="#{beanEventos.nombre}"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel value="Descripcion Evento"/>
                            <h:inputText id="desc"  value="#{beanEventos.descripcion}"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:outputLabel value="Fecha Evento"/>
                            <p:calendar value="#{beanEventos.fec}" 
                                        showButtonPanel="true"/>                      
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:selectBooleanCheckbox value="#{beanEventos.vigencia}"/> 
                            <h:outputText value="Vigencia" style="font-weight:bold"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <h:commandButton value="Modificar" action="#{DAOEventos.modificarEvento()}" />
                        </td>
                    </tr>
                </table>
            </h:form> 
        </p:dialog>
    </h:panelGroup>

    <h:form id="form3">     
    <p:commandButton id="showDialogButton"  value="Agregar" oncomplete="dlg.show()" /> 

    <p:dialog header="Enter FirstName" widgetVar="dlg" resizable="false" id="dialogo"  >  


            <table>
                <tr>
                    <td>
                        <h:outputLabel value="Nombre Evento "/>
                        <h:inputText id="nombre"  value="#{beanEventos.nombre}"/>
                    </td>
                </tr>
                <tr>
                    <td>
                        <h:outputLabel value="Descripcion Evento "/>
                        <h:inputText id="desc"  value="#{beanEventos.descripcion}"/>
                    </td>
                </tr>

                <tr>
                    <td>
                        <h:outputLabel value="Fecha de Evento"/>
                        <p:calendar value="#{beanEventos.fec}" id="cal" showButtonPanel="true"/>  
                    </td>
                </tr>

                <tr>
                    <td>
                        <h:commandButton value="Registrar Evento"
                                         action="#{DAOEventos.insertarEvento()}"/>
                    </td>
                </tr>
            </table>

    </p:dialog>  

</h:form>  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM