原始异常INFO:java.lang.ArithmeticException:/ by zero java.lang.ArithmeticException:/ by zero [英] Primefaces exception INFO: java.lang.ArithmeticException: / by zero java.lang.ArithmeticException: / by zero

查看:211
本文介绍了原始异常INFO:java.lang.ArithmeticException:/ by zero java.lang.ArithmeticException:/ by zero的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了LazyLoading for datatable。当我通过分页使用datatable时,我得到以下异常。

  com.sun.faces.context.PartialViewContextImpl processPartial 
INFO:java.lang.ArithmeticException:/ by zero
java.lang.ArithmeticException:/ by零
在org.primefaces.model.LazyDataModel.setRowIndex(LazyDataModel.java:62)
在org.primefaces.component.api.UIData.setRowModel( UIData.java:411)
在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;
}

JSF

 < H:形式> 
< p:dataTable id =dataTablevar =reqlazy =truevalue =#{reqMB.lazyModel}
paginator =truerows =10
paginatorTemplate ={CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}
rowsPerPageTemplate =5,10,15>

DAO获取行数。

  int count =((Long)sessionFactory.getCurrentSession()。createQuery 
(从请求中选择count(*))uniqueResult())intValue()

更新1

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


解决方案

根据评论#23在问题跟踪器的原点以下应该解决这个问题

  @Override 
public void setRowIndex(int rowIndex){
/ *
*以下是在祖先(LazyDataModel)中:
* this。 rowIndex = rowIndex == -1? rowIndex:(rowIndex%pageSize);
* /
if(rowIndex == -1 || getPageSize()== 0){
super.setRowIndex(-1);
}
else
super.setRowIndex(rowIndex%getPageSize());
}


I have implemented LazyLoading for datatable. When I run through datatable by using pagination I am getting the following exceptions.

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;
         }

JSF

<h:form>
        <p:dataTable id="dataTable" var="req" lazy="true" value="#{reqMB.lazyModel}"
            paginator="true" rows="10"
            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
            rowsPerPageTemplate="5,10,15">

DAO for getting row count.

int count = ((Long)sessionFactory.getCurrentSession().createQuery
("select count(*) from Request").uniqueResult()).intValue();

Update 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)

解决方案

According to comment #23 in the issue tracker of primefaces the following should fix that problem

@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());
}

这篇关于原始异常INFO:java.lang.ArithmeticException:/ by zero java.lang.ArithmeticException:/ by zero的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆