primefaces-extensions / primefaces-extensions.github.com

Organization repo, only for homepage, wiki and issue tracker
https://primefaces-extensions.github.io/
68 stars 22 forks source link

CommandButtonSingleClick: Problem in Datatable #761

Closed melloware closed 4 years ago

melloware commented 4 years ago

If you have a Datatable with a CommandButton in the first column.

<p:column>
    <p:commandButton id="btnActions" value="Button" 
         oncomplete="alert('#{component.clientId}');" immediate="true" process="@this" />
<p:column>

Because in encodeMarkup we are calling button.resolvewidgetVar() it is resolving it incorrectly.

All of the buttons in my table are being rendered with widgetVar :0:

frmMain:tblTest:0:btnActions
frmMain:tblTest:0:btnActions
frmMain:tblTest:0:btnActions
frmMain:tblTest:0:btnActions

instead of

frmMain:tblTest:0:btnActions
frmMain:tblTest:1:btnActions
frmMain:tblTest:2:btnActions
frmMain:tblTest:3:btnActions
melloware commented 4 years ago

OK I was able to reproduce it! pfe-761.zip

if you run that sample app and press each button they will all say "button0" in the alert. However if you remove the CommandButtonSingleClick renderer it works fine and each button reports its proper value.

jepsar commented 4 years ago

Let me have a look. I think we can use PrimeFaces.getWidgetById(clientId).

jepsar commented 4 years ago

Weird.. the rendered onclick of button 0:

PrimeFaces.bcn(this,event,[function(event){var w=PF('widget_j_idt5_tblCars_0_btnActions');if(w){w.disable();};},function(event){PrimeFaces.ab({s:"j_idt5:tblCars:0:btnActions",f:"j_idt5",p:"j_idt5:tblCars:0:btnActions",onco:function(xhr,status,args,data){var w=PF('widget_j_idt5_tblCars_0_btnActions');if(w){w.enable();};alert('j_idt5:tblCars:0:btnActions');;}});return false;}]);

and button 4:

PrimeFaces.bcn(this,event,[function(event){var w=PF('widget_j_idt5_tblCars_4_btnActions');if(w){w.disable();};var w=PF('widget_j_idt5_tblCars_3_btnActions');if(w){w.disable();};var w=PF('widget_j_idt5_tblCars_2_btnActions');if(w){w.disable();};var w=PF('widget_j_idt5_tblCars_1_btnActions');if(w){w.disable();};var w=PF('widget_j_idt5_tblCars_0_btnActions');if(w){w.disable();};},function(event){PrimeFaces.ab({s:"j_idt5:tblCars:4:btnActions",f:"j_idt5",p:"j_idt5:tblCars:4:btnActions",onco:function(xhr,status,args,data){var w=PF('widget_j_idt5_tblCars_4_btnActions');if(w){w.enable();};var w=PF('widget_j_idt5_tblCars_3_btnActions');if(w){w.enable();};var w=PF('widget_j_idt5_tblCars_2_btnActions');if(w){w.enable();};var w=PF('widget_j_idt5_tblCars_1_btnActions');if(w){w.enable();};var w=PF('widget_j_idt5_tblCars_0_btnActions');if(w){w.enable();};alert('j_idt5:tblCars:0:btnActions');;}});return false;}]);

jepsar commented 4 years ago

The issue is with prefixing and setting the attributes: https://github.com/primefaces-extensions/core/blob/primefaces-extensions-8.0/src/main/java/org/primefaces/extensions/renderer/CommandButtonSingleClickRenderer.java#L35-L36

melloware commented 4 years ago

Yeah its like its additive.

melloware commented 4 years ago

Also go to this example in the showcase: https://www.primefaces.org/showcase-ext/sections/slideout/basicUsage.jsf

You can only click the buttons once.

jepsar commented 4 years ago

Also go to this example in the showcase: https://www.primefaces.org/showcase-ext/sections/slideout/basicUsage.jsf

You can only click the buttons once.

Hmm.. those buttons don't have an action. I'll throw in a check on that as well.