Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Primefaces异常信息:java.lang.arithmetricException:/by zero java.lang.arithmetricException:/by zero_Java_Exception_Jsf 2_Primefaces_Lazy Loading - Fatal编程技术网

Primefaces异常信息:java.lang.arithmetricException:/by zero java.lang.arithmetricException:/by zero

Primefaces异常信息:java.lang.arithmetricException:/by zero java.lang.arithmetricException:/by zero,java,exception,jsf-2,primefaces,lazy-loading,Java,Exception,Jsf 2,Primefaces,Lazy Loading,我已经为datatable实现了LazyLoading。当我使用分页运行datatable时,我得到了以下异常 com.sun.faces.context.PartialViewContextImpl processPartial INFO: java.lang.ArithmeticException: / by zero java.lang.ArithmeticException: / by zero at org.primefaces.model.LazyDataModel.setR

我已经为datatable实现了LazyLoading。当我使用分页运行datatable时,我得到了以下异常

com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
    at org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
    at org.primefaces.component.api.UIData.setRowModel(UIData.java:411)
    at org.primefaces.component.api.UIData.setRowIndex(UIData.java:403)
ManagedBean

@PostConstruct
    public LazyDataModel<Request> getLazyModel() {
          if (lazyModel == null) {
           lazyModel = new LazyDataModel<Request>() {

            @Override
            public List<Request> load(int startingAt, int maxPerPage, String sortField,
                       SortOrder sortOrder, Map<String, String> filters) {
             return getRequestService().getRequest(startingAt, maxPerPage, sortField, sortOrder, filters);
            }
           };
           lazyModel.setRowCount(getRequestService().getRequestCount());           

          }
          return lazyModel;
         }
更新1

com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
    at org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
    at org.primefaces.component.api.UIData.setRowModel(UIData.java:411)
    at org.primefaces.component.api.UIData.setRowIndex(UIData.java:403)
    at org.primefaces.component.api.UIData.processChildren(UIData.java:291)
    at org.primefaces.component.api.UIData.processPhase(UIData.java:263)
    at org.primefaces.component.api.UIData.processDecodes(UIData.java:229)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:641)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at javax.faces.component.UIForm.visitTree(UIForm.java:344)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
根据评论,以下内容应能解决该问题

@Override
public void setRowIndex(int rowIndex) {
    /*
     * The following is in ancestor (LazyDataModel):
     * this.rowIndex = rowIndex == -1 ? rowIndex : (rowIndex % pageSize);
     */
    if (rowIndex == -1 || getPageSize() == 0) {
        super.setRowIndex(-1);
    }
    else
        super.setRowIndex(rowIndex % getPageSize());
}

您是否有可能在
maxPerPage
中为零?@AlexZam
maxPerPage
在我测试时始终为5或10,这在datatable下拉列表中是默认值。我从未更改。此问题表明您的
中的
rows=“0”
。你在运行你认为正在运行的代码吗?也许您有一个
rows=“#{bean.rows}”
在回发时返回
0
。@BalusC我设置了
rows=“10”
,这是硬编码的,不是动态的。我正在设置的动态值是
lazModel.setRowCount(getRequestService().getRequestCount())调试此问题的最佳方法是什么?在
LazyDataModel
pageSize
属性上放置一个“修改”断点(或者在
setPageSize()
方法上仅放置一个“访问”断点,在该方法中检查是否曾以
0
作为值调用它)。在尝试设置
0
的值时,请检查stacktrace中的who和why。谢谢。我已经注意到,当范围是视图时,这个问题似乎不会出现。
com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.ArithmeticException: / by zero
java.lang.ArithmeticException: / by zero
    at org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
    at org.primefaces.component.api.UIData.setRowModel(UIData.java:411)
    at org.primefaces.component.api.UIData.setRowIndex(UIData.java:403)
    at org.primefaces.component.api.UIData.processChildren(UIData.java:291)
    at org.primefaces.component.api.UIData.processPhase(UIData.java:263)
    at org.primefaces.component.api.UIData.processDecodes(UIData.java:229)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:641)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at javax.faces.component.UIForm.visitTree(UIForm.java:344)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
    at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
@Override
public void setRowIndex(int rowIndex) {
    /*
     * The following is in ancestor (LazyDataModel):
     * this.rowIndex = rowIndex == -1 ? rowIndex : (rowIndex % pageSize);
     */
    if (rowIndex == -1 || getPageSize() == 0) {
        super.setRowIndex(-1);
    }
    else
        super.setRowIndex(rowIndex % getPageSize());
}