0

which pick data from DB (postgre),

this page first list the data in a list then i have a commandlink "modificar" wich carry the data from the element clicked in a dialog but i dont know why the commandbutton in this dialog doesnt invoke the method "DAOEventos.modificarEvento" .... at the end i have a button that register data to the db from a dialog, this is OK works

the only problem i have is with the dialog comes from commandlink!

i made a debug and the problem is with "p:calendar" if i kick that, the method was invoked, but i need that value from the 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>

MitoCode
  • 319
  • 2
  • 10
  • 25
  • 3
    http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked/2120183#2120183 – BalusC Mar 13 '13 at 18:17

2 Answers2

1

You are nesting one HTML form inside another HTML form which is not a valid concept in HTML. Even if you doing this in JSF ultimate rendering component will be HTML only.So, remove <h:form id="form"> from your code or try to keep all the above code inside single form.

Check here : How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?

Community
  • 1
  • 1
SRy
  • 2,901
  • 8
  • 36
  • 57
1

As SrinivasR said, you shouldn't (although this may work fine) nest forms. But I think the issue here is with the place where you are defining your:

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

You should put it outside the datatable.

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

Laabidi Raissi
  • 3,263
  • 1
  • 22
  • 28
  • actually i separete in 3 forms for the first part then the second dialog and the third dialog, but i have problems with the update value from the first dialog modaldialog2 – MitoCode Mar 13 '13 at 19:09
  • Can you give some more explanations ? Did you put the dialog outside datatable ? what kind of "problems with the update..." did you encounter ? – Laabidi Raissi Mar 13 '13 at 19:25
  • well, i put the dialog outside, but can you put me the exactly code please – MitoCode Mar 13 '13 at 19:27
  • Ok, it's very simple to try my solution, please see my answer updated – Laabidi Raissi Mar 13 '13 at 19:33
  • i do that, but now the problem is the first dataTable the list value doesnt work, and i if i kick the "upadte" from the commandLink", the value list work the method doesnt invoke – MitoCode Mar 13 '13 at 20:23
  • error: Cannot find component with identifier "modalDialog2" --- its from update commandlink – MitoCode Mar 13 '13 at 20:30
  • ah yes, of course, Sorry, please re-use my updated answer. in fact, since we are not using prependId="false" in the form, the id of the dialog will be:= form:modalDialog2 – Laabidi Raissi Mar 13 '13 at 20:32
  • now Cannot find component with identifier "form:modalDialog2" =/ – MitoCode Mar 13 '13 at 20:37
  • ok, according to BalusC (http://stackoverflow.com/questions/4573190/jsf-primefaces-update-attribute-does-not-update-component/4574266?noredirect=1) you should put the dialog inside "element which is always available in the HTML DOM tree", so please try my edited answer – Laabidi Raissi Mar 13 '13 at 20:49
  • also i have the same structure that i wrote at the begining and works but i only have "h" labels but in this case i have "p" label from calender but i need that value – MitoCode Mar 13 '13 at 20:50
  • Let me explain you the situation. When not using the right approach to develop a functionality, it may work somehow, but whenever you need some advanced features, you will encounter many problems. And here in your case, there two issues with your code: 1) nested forms and 2) defining p:dialog inside datatable – Laabidi Raissi Mar 13 '13 at 20:55
  • Any news here ? if the problem still remains, just come to Skype (to avoid extended discussions in SO) – Laabidi Raissi Mar 13 '13 at 21:24