【问题标题】:my commandbutton doesnt work, JSF + primefaces?我的命令按钮不起作用,JSF + primefaces?
【发布时间】:2013-03-13 16:20:23
【问题描述】:

从数据库(postgre)中挑选数据,

此页面首先列出列表中的数据 然后我有一个命令链接“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>

【问题讨论】:

标签: jsf primefaces invoke


【解决方案1】:

您将一个 HTML form 嵌套在另一个 HTML form 中,这在 HTML 中不是一个有效的概念。即使您在 JSF 中执行此操作,最终渲染组件也只会是 HTML。所以,删除 &lt;h:form id="form"&gt; 来自您的代码或尝试将上述所有代码保留在单个表单中。

在这里检查: How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?

【讨论】:

    【解决方案2】:

    正如 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>  
    

    【讨论】:

    • 实际上我将第一部分分为 3 种形式,然后是第二个对话框和第三个对话框,但我对第一个对话框 modaldialog2 的更新值有疑问
    • 你能再解释一下吗?您是否将对话框放在数据表之外?你遇到了什么样的“更新问题……”?
    • 好吧,我把对话框放在外面,但是你能把确切的代码给我吗
    • 好的,试试我的解决方案很简单,请看我更新的答案
    • 我这样做了,但现在问题是第一个数据表列表值不起作用,如果我从 commandLink 中踢出“upadte”,则值列表工作该方法不会调用跨度>
    猜你喜欢
    • 2017-10-04
    • 1970-01-01
    • 2013-10-24
    • 2012-09-02
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 2012-10-20
    相关资源
    最近更新 更多