0

This might be an odd question but we are required to suppress a certain type of exception from a certain method from printing on to our debug console.

This exception I am talking about is happening on LazyDataModel for Primefaces where the setter method is throwing Arithmetic Exception: / by zero when in a certain phase of the datatable lifecycle the pageSize is 0 and it goes on to throw that exception.

The parent class method from the Primefaces framework for LazyDataModel.class is:

public void setRowIndex(int rowIndex) {
    this.rowIndex = rowIndex % this.pageSize;
}

The common solution out there is below:

  @Override
  public void setRowIndex(int rowIndex) {
    if (rowIndex == -1 || getPageSize() == 0) {
      super.setRowIndex(-1);
    }
    else {
      super.setRowIndex(rowIndex % getPageSize());
    }
  }

However, the solution posted above still manages to throw Arthimetic Exception: / by zero when pageSize is 0. We've tried catching the exception and manipulating the values in our method so the Exception is not thrown but that breaks the UI.

When we don't have the override method there everything works fine but the exception is still printed. Our management does not want this.

The solution I am thinking of now is to remove my override method and try to suppress the exception from JVM or the method itself. And the management seems happy to accept that. On those lines is there any approach out there I can try?

Update 1: As requested by PSo, we are not explicitly setting pageSize anywhere (backend or frontend).

Datatable Definition in the view file

        <p:dataTable widgetVar="myWidgetName" var="myDataVariable" value="#{myManagedBean.dataList}" rowIndexVar="myRowIndexVariable" id="myDataTableId"
                     styleClass="myStyleClass" emptyMessage="No Records Found"
                     rowStyleClass="myRowStyleClass"
                     scrollable="false"
                     paginator="true"
                     rows="5"
                     paginatorAlwaysVisible="true"
                     paginatorPosition="both"
                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {JumpToPageDropdown} {PageLinks} {NextPageLink} {LastPageLink}"
                     rowsPerPageTemplate="10" 
                     selection="#{myManagedBean.mySelectedRecord}"
                     rendered="true">

            <p:column headerText="#">
            <h:outputText>#{myDataRowIndex}</h:outputText></p:column>
            <p:column styleClass="myColumnStyleClass">
                
            </p:column>

        </p:dataTable>
Obaid
  • 75
  • 2
  • 9
  • 1
    could you paste more on the primefaces related code as well? how do you pass the pageSize? what happened in the on load? it suppose to be something and never related to database. and it should be manageble with a single if. – PSo Nov 19 '20 at 09:48
  • Hey @PSo, updated my answer with your request. – Obaid Nov 19 '20 at 10:11
  • We could try to suppress it using the Logger library we use...? – Obaid Nov 19 '20 at 12:11
  • 1
    i aint sure but would you mind trying to change the rowsPerPageTemplate, just to ensure pagesize is always not 0, calling datatable.paginator.setRowsPerPage() from JS, example here: https://stackoverflow.com/questions/18908722/how-do-you-update-the-page-size-of-a-primefaces-datatable-dynamically – PSo Nov 20 '20 at 04:31

0 Answers0