9 Replies Latest reply on Dec 10, 2007 7:01 AM by panky_p

    how to delete selected record using modalPanel?

    panky_p Novice

      Hi,
      I want to delete selected record from data table using command button.
      on command button click modalPanel will pop up which will delete selected record. for that I am using data model section.
      But when i try to delete record i tdelete first record only!!
      When I remove modalPanel from delete button it works properly and deletes selected record properly why is it so???

      Can any one help me out!!!

      Thanks
      Panky

        • 1. Re: how to delete selected record using modalPanel?
          Jawher Moussa Newbie

          Hi.
          It's really hard to help you without viewing your code ...

          So, personally, I do it this way:
          - I use the a4j commandLink or commandButton to call a method called selectBean which simply extracts the getRowData from the DataModel and save it in a field.
          - I also add the oncomplete attribute to my commandLink/Button which calls the JS function to show my ModelPanel.
          - In my ModalPanel, I'am able to show a message containing infos about the selected bean (thanks to the first step). I also include a confirm commandLink/Button which calls the actual delete method.

          Regards.

          • 2. Re: how to delete selected record using modalPanel?
            panky_p Novice

            Thanks for reply it seem it will work for me
            but how can i getRowData from DataModel?
            I am not able to do that!!!

            also my problem is how can I send data to modalPanel for edit if Edit button will be clicked??


            Thanks for reply

            Panky

            • 3. Re: how to delete selected record using modalPanel?
              panky_p Novice

              Hi djo

              Thanks alot I got it working !!
              I was struggling with it from last two days
              hanks for help!!!

              Panky

              • 4. Re: how to delete selected record using modalPanel?
                panky_p Novice

                Hi djo,

                it is working on a4j:commandButton but not working on commandLink.
                Gives script error object require!!
                why is it so?

                Thanks

                Panky

                • 5. Re: how to delete selected record using modalPanel?
                  Jawher Moussa Newbie

                  Well, I'm not sure to understand the error you get, but in my case, this method works perfectly with the commandLink (a4j). May you show your JSF code please ? and the complete error message/stack trace ?
                  thx

                  • 6. Re: how to delete selected record using modalPanel?
                    panky_p Novice

                    Hi,
                    there is no stack trace error it is something like script error

                    <f:subview>
                    <h:dataTable value="#{myList}" var="newList">
                    <h:column>
                    <f:facet name="header">Car Name</f:facet>
                    #{newList.myCar}
                    </h:column>
                    <h:column>
                    <f:facet name="header">Type</f:facet>
                    <a4j:commandLink action="#{carBean.editCar()}" value="Edit"/>
                    <a4j:commandLink value="Delete" action="#{carBean.indexCar()}" oncomplete="javascript:Richfaces.showModalPanel('deleteCar',{width:500, top:300})"/>
                    </h:column>
                    </h:dataTable>
                    </f:subview>
                    
                    

                    and modalPanel is
                    <rich:modalPanel id="deleteCar" minHeight="200" minWidth="200"
                    height="200" width="350" zindex="2000">
                    <f:facet name="header">
                    <h:outputText value="Delete Car" />
                    </f:facet>
                    <f:facet name="controls"><h:graphicImage value="close" style="cursor:pointer" onclick="Richfaces.hideModalPanel('deleteCar')" />
                    </f:facet>
                    <h:form id="deleteCarForm">
                    <div>
                    <table>
                    <tr>
                    <td align="center" ><h:outputLabel value="Delete This Car?"/> </td>
                    </tr>
                    <tr>
                    <td style="height:50px" colspan="2" align="center">
                    <h:commandButton type="button" value=" Yes " action="#{carBean.deleteCar()}" />
                    <h:commandButton type="button" value=" No " action="javascript:Richfaces.hideModalPanel('deleteCar')" />
                    </td>
                    </tr>
                    </table>
                    </div>
                    </h:form>
                    </rich:modalPanel>


                    • 7. Re: how to delete selected record using modalPanel?
                      Jawher Moussa Newbie

                      Still, without a description of what error are you getting, I can't see how we're supposed to find out what's wrong.
                      Your code seems fine to me.
                      Maybe you should upgrade to the latest version of RichFaces ? the 3.1.2 SP 1 ?

                      Tip: If you are testing in Firefox, you may find out what's wrong by Opening the Errors Console (Tools > Error Console).

                      • 8. Re: how to delete selected record using modalPanel?
                        panky_p Novice

                        Hi djo,
                        I am getting

                        Error: uncaught exception: [Exception... "Object cannot be created in this context" code: "9" nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)" location: "http://localhost:8080/test/car/carmain.seam?conversationId=5 Line: 17"]
                        
                        
                        Error: this._form has no properties
                        Source File: http://localhost:8080/test/a4j.res/org.ajax4jsf.framework.ajax.AjaxScript
                        Line: 74

                        on error console.There is no stack trace it shows alert message
                        Run time error has occurred Error:Object required

                        I am not getting why?

                        Thanks

                        • 9. Re: how to delete selected record using modalPanel?
                          panky_p Novice

                          Hi,
                          I solved it by adding<h:form>

                          <h:form>
                          <f:subview>
                          <h:dataTable value="#{myList}" var="newList">
                          <h:column>
                          <f:facet name="header">Car Name</f:facet>
                          #{newList.myCar}
                          </h:column>
                          <h:column>
                          <f:facet name="header">Type</f:facet>
                          <a4j:commandLink action="#{carBean.editCar()}" value="Edit"/>
                          <a4j:commandLink value="Delete" action="#{carBean.indexCar(ind)}" oncomplete="javascript:Richfaces.showModalPanel('deleteCar',{width:500, top:300})"/>
                          </h:column>
                          </h:dataTable>
                          </f:subview>
                          </h:form>
                          but now index is not working properly when delete it first time delete first element, then if again click delete it deletes properly selected one.
                          In my bean class carBean.java to extract row data I am using
                          public String indexCar (Integer ind)
                           {
                           if(carList.size() != 0)
                           {
                           carList.get(index);
                           }
                           return result;
                           }


                          Why is it so?

                          I am trying to find it out.

                          Thanks