onclick javascript confirm on commandLink

UI Components for JSF
Post Reply
mSephiroth
Posts: 47
Joined: 15 Mar 2010, 22:09
Location: Guatemala
Contact:

04 Oct 2010, 03:44

Hello

I am using primefaces 2.2M1 and I im trying to add a javascript confirm dialog on a commandLink in a DataTable with the follow code:

Code: Select all

                                    <p:dataTable value="#{TareaMBean.obtenerTareasDeCurso(curso.cursoActual)}" var="item"
                                                 emptyMessage="No se encontraron tareas en este curso"
                                                 paginator="true" rows="10" >

                                       .....                                       
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Eliminar"/>
                                            </f:facet>
                                            <h:commandLink title="Eliminar" action="#{TareaMBean.borrarTarea(item)}"
                                                           onclick="if(confirm('Esta seguro de eliminar esta tarea? Tambien se borraran los trabajos entregados'))return true; else return false;">
                                                <h:graphicImage alt="eliminar" url="/images/delete.gif"/>
                                            </h:commandLink>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Visible"/>
                                            </f:facet>                                            
                                        </p:column>
                                    </p:dataTable>
                                
the confirmdialog is showed but when I confirm the action, it doesnt execute the action. when I set ajax = "false" it works, but with ajax enabled it doesnt works.

May be I missing something.

Thanx for help
Glassfish 3.x, Mojarra 2.1.0 (FCS 2.1.0-b11), Netbeans 6.9, PF 2.2.1, Ubuntu 9.10

I will...never be a mere memory!!

timotius_pamungkas
Posts: 117
Joined: 19 May 2010, 03:50

04 Oct 2010, 05:40

instead of using standard js confirm(), primefaces has a confimDialog component for this purpose (which is also better look and feel). Find how to use it here: http://www.primefaces.org/showcase/ui/confirmDialog.jsf
Tomcat 7.0.25
Mojarra 2.1.6
Primefaces 3.1, 3.2
Firefox 10 and IE 7/IE 8

mSephiroth
Posts: 47
Joined: 15 Mar 2010, 22:09
Location: Guatemala
Contact:

04 Oct 2010, 16:01

Hi, I have tested the p:confirmDIalog, but in the case of a table, I create a confirmDialog for each row, is that afecting the performance of the application?
Glassfish 3.x, Mojarra 2.1.0 (FCS 2.1.0-b11), Netbeans 6.9, PF 2.2.1, Ubuntu 9.10

I will...never be a mere memory!!

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

04 Oct 2010, 17:06

You can use one confirmDialog for all rows.

timotius_pamungkas
Posts: 117
Joined: 19 May 2010, 03:50

05 Oct 2010, 02:41

as optimus says, one confirm dialog is enough. If you need to pass id to be deleted, you can do so by adding attribute "selection" of datatable, or using f:attribute/f:setPropertyActionListener to pass the desired value
Tomcat 7.0.25
Mojarra 2.1.6
Primefaces 3.1, 3.2
Firefox 10 and IE 7/IE 8

mSephiroth
Posts: 47
Joined: 15 Mar 2010, 22:09
Location: Guatemala
Contact:

05 Oct 2010, 23:46

oh ya, I'll test

thanks
Glassfish 3.x, Mojarra 2.1.0 (FCS 2.1.0-b11), Netbeans 6.9, PF 2.2.1, Ubuntu 9.10

I will...never be a mere memory!!

mSephiroth
Posts: 47
Joined: 15 Mar 2010, 22:09
Location: Guatemala
Contact:

07 Oct 2010, 17:45

Hi, I have tested the solutions you suggested and it works, but when I do an ajax update from de confirmdialog, sometimes it works, and sometimes didnt.

I generate tables in a eachfor tag and then use a confirmdialog for confirm a remove action for a row in each table.

any idea?
Glassfish 3.x, Mojarra 2.1.0 (FCS 2.1.0-b11), Netbeans 6.9, PF 2.2.1, Ubuntu 9.10

I will...never be a mere memory!!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 32 guests