3

I have a p:datatable in primefaces and i have different listeners for differents ways to select row event in datatable.

I need identify when the selected row in the table is already selected, how can i do that?

I need this because i dont wonna that p:blockUI runs when i select row in the table that is already selected.

There is my page code:

...
<pe:blockUI autoShow="true" 
            source="itemsDT" 
            event="rowSelect" 
            target=":processTab">
    <au:loading />                                    
</pe:blockUI>
<p:dataTable widgetVar="processesTable" 
             id="itemsDT" 
             var="item" 
             value="    
             {tasksbacking2.availableProcesses}" 
             selection="#{tasksbacking2.selectedProcess}" 
             rowKey="#{item.id}"
             tableStyleClass="table
             table-condensed table-bordered"   
             resizableColumns="true">

    <p:ajax event="rowSelect" 
            listener="#{tasksbacking2.onClickFillDetails}" 
            update="@this,:processTab,:menuForm:menuBar" />
    ...
</p:dataTable>
...

On managed bean i have this listener:

...
public void onClickFillDetails(SelectEvent event) {
      AnoProcess clickedProcess = (AnoProcess) event.getObject();
      setSelectedProcess(clickedProcess);
      Movement currentMovement = this.getProcessesLastMovement().get(clickedProcess);
      if (currentMovement != null && !currentMovement.isViewed()) {
            markAsRead(processes);
      }
   ...
}
wittakarn
  • 3,074
  • 1
  • 16
  • 30
Marin
  • 960
  • 1
  • 9
  • 35
  • are you using primefaces 5.1? Or can you tell your primefaces lib version? Becouse i can't see some attributes that you use on `p:blockUI, or you are using other component? – Cold Oct 09 '14 at 14:18
  • i use primefaces 5.0 and use primefaces-extensions (for blockUI with events catch). See this http://www.primefaces.org/showcase-ext/views/blockUI.jsf;jsessionid=93wiz0dle6vvsw68azz6fws8 – Marin Oct 09 '14 at 14:22
  • Oh, ok. You can resolve this using `RequestContext` and run `pe:blockUI` when the new selected item is different of last selected item. – Cold Oct 09 '14 at 14:25
  • can you change may edition replacing `p:blockUI` to `pe:blockUI` please, was my mistake. – Cold Oct 09 '14 at 14:29
  • 1
    change the context is not the solution. yes I edited again . My solution is probably in the onstart event in p:ajax like this: – Marin Oct 09 '14 at 14:39
  • Do you want to your rowselect ajax listener to NOT call `onClickFillDetails` if row is already selected????right?? – Kishor Prakash Oct 15 '14 at 03:48

2 Answers2

2

Here is the script to check for duplicate click on same row.
Put this script below your p:dataTable code.

<script type="text/javascript">
    var prevRow ;
    function checkDupRowClick(){
        var currRow = $('tr.ui-widget-content.ui-datatable-selectable[aria-selected="true"]');
        if($(currRow).is($(prevRow))){
            //selected or clicked same row so return FALSE to prevent p:ajax from executing
            return false;
        }else{
            //selected or clicked different row so return TRUE to allow p:ajax to execute
            prevRow = currRow;
            return true;
        } 
    }
</script>

AND use function as a return parameter for p:ajax

<p:ajax event="rowSelect" onstart="return checkDupRowClick();" />

Post comment if you require more explanation.

Kishor Prakash
  • 7,381
  • 10
  • 53
  • 88
  • this script work. but when return false the page not work more. why? my p:ajax is: – Marin Oct 15 '14 at 13:26
  • Are there any JS console errors? How many Tables are there on your page? – Kishor Prakash Oct 15 '14 at 13:31
  • 2 tables but i know this and change script to this: var prevRow; function checkDupRowClick() { var currRow = $('#formDTItems tr.ui-widget-content.ui-datatable-selectable[aria-selected="true"]'); if ($(currRow).is($(prevRow)) { return false; } else { prevRow = currRow; return true; } } – Marin Oct 15 '14 at 13:50
1

I think that you need is some function in js and apply this in onstart.

like that

<p:ajax event="rowSelect" onstart="???" />
kimk
  • 116
  • 4