3

Here is my commandButton inside a datatable column which job is to delete the associated line object:

   <p:column style="width:6%;text-align:center"
   headerText="Delete">
    <p:commandButton icon="ui-icon-close"
     title="Delete release #{release.name}"
     actionListener="#{releaseBean.deleteRelease(release)}"
     process="@this" update=":display :form2:releaseList">
        <p:confirm
          header="Confirm deleting release #{release.name}"
          message="Are you really sure you want to delete release #{release.name}?"
          icon="ui-icon-alert" />
    </p:commandButton>
   </p:column>

I want the name of the release to be displayed in the delete confirm message (Are you really sure you want to delete release "XYZ" ?).. But the problem is that the name of the release "XYZ" is not displayed nor in the header of <p:confirm> neither in the message; but it's displayed in the <p:commandButton> title.

What have I done wrong? Thank you.


EDIT:

I tried to modify the commandButton and add the setPropertyActionListener:

    <p:commandButton icon="ui-icon-close"
         title="Delete release #{release.name}"
         actionListener="#{releaseBean.deleteRelease(release)}"
         process="@this" update=":display :form2:releaseList">
         <f:setPropertyActionListener
         target="#{gestionReleaseBean.selectedRelease}"
         value="#{release}" />            
         <p:confirm
              header="Confirm deleting release #{release.name}"
              message="Are you really sure you want to delete release #{release.name}?"
              icon="ui-icon-alert" />
    </p:commandButton>

and in the bean I added the property selectedRelease and it's getter/setter.

It didn't work...

Sinda MOKADDEM
  • 796
  • 2
  • 12
  • 35
  • Is the commandButton itself ajax-updated, i.e. does the `update` attribute of commandButton contain the id of a component embedding it? – perissf Jul 15 '14 at 11:58
  • the update concerns a `` and the whole `` (in which is the button) in order to suppress the freshly deleted line. Why? – Sinda MOKADDEM Jul 15 '14 at 12:05
  • Is it possible to use a standalone `dialog` or `confirmDialog` with an attribute from the bean instead of a `p:confirm` with a global `confirmDialog`? – rion18 Jul 16 '14 at 03:04
  • 1
    Seems like you've stumbled on a possible bug @Siho. I've tested and confirmed it myself, the `` cannot evaluate the local variable of the datatable. It appears to be able to evaluate only values that are available during page build, not during page render. What this means is that only a value that's available in your backing bean, before the datatable is rendered, will make it into the markup. You can check the generated javascript yourself to confirm that the js responsible for the popup itself has empty values where your `var` should be – kolossus Jul 16 '14 at 04:59
  • @rion18 how to do that, you mean like this (from PF user guide) ` ` – Sinda MOKADDEM Jul 16 '14 at 08:32
  • Kinda... I was talking about having a variable called `selectedObject` (or something) and referencing `#{bean.selectedObject.name}` from the dialog... – rion18 Jul 16 '14 at 08:35
  • and how to set the value of that `selectedObject`? – Sinda MOKADDEM Jul 16 '14 at 08:45
  • Adding an `` inside your `p:commandButton` – rion18 Jul 18 '14 at 04:40
  • @rion18 It didn't work :( I edited my question to specify what I've done – Sinda MOKADDEM Jul 18 '14 at 09:51
  • In this case `p:confirm` will not work. You need to create a dialog or a confirmDialog outside of the table and reference that component. – rion18 Jul 18 '14 at 17:33
  • But this is exactly the code I wrote, isn't it? – Sinda MOKADDEM Jul 19 '14 at 21:49
  • No, my confirm dialog uses `#{gestionReleaseBean.selectedRelease.name}?` and yours takes `#{release.name}`... – rion18 Jul 25 '14 at 19:42
  • I just tried that and it still doesn't display the release name – Sinda MOKADDEM Jul 28 '14 at 20:17

1 Answers1

0

If you dont mind some extra code lines then you can achieve this as below,

First place a dialog out side datatable

<p:dialog modal="true" header="Confirm" widgetVar="wgc" >
 <h:outputText id="msg" />
 <h:inputHidden id="idh" value="#{releaseBean.id}" />
 <p:commandButton value="Delete" action="#{bean.delete()}" />
 <p:commandButton value="Cancel" type="button" onclick="PF('wgc').hide()" />
</p:dialog>

in your javascript section add this

function confirm(id,name){
 document.getElementById('msg').innerHtml='Are you sure to delete ' +  name;
 document.getElementById('idh').value=id;
 PF('wgc').show();
}

and then in datatable delete button

<p:commandButon type="button" 
                value="Delete" 
                onclick="confirm(#{release.id},'#{release.name}')" />
alessandro
  • 19
  • 8