Primefaces数据表过滤器函数与com.sun.lang.el冲突

时间:2017-08-08 16:41:33

标签: jsf primefaces datatable

我是primefaces的新手,并且正在使用primefaces版本6.1实现数据表。我创建了一个数据表,并在字段中添加了过滤功能,类似于https://www.primefaces.org/showcase/ui/data/datatable/filter.xhtml

这个演示应用程序对我来说很好,但是一旦我将代码移动到我的应用程序,我就得到了 java.lang.IllegalArgumentException: Cannot convert true of type class java.lang.Boolean to class java.lang.Integer

以下详细信息 -

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
    <h:form>
        <p:dataTable id="caId" var="characteristicsAnalysis"
                     value="#{characteristicsAnalysisBean.characteristicsAnalysisList}" paginatorPosition="bottom"
                     filteredValue="#{characteristicsAnalysisBean.filteredCA}" editable="true"
                     style="margin-bottom:20px" rows="10" widgetVar="caTableId" paginator="true"
                     paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15" scrollable="true" scrollWidth="100%" scrollHeight="341"
                     sortBy="#{characteristicsAnalysisBean.preSortOrder}" sortMode="multiple">

            <f:facet name="header">
                Characteristics Scorecard Table
                <div style="position:absolute; right: 13%; margin-top: -1.9%;">
                    <p:commandButton value="Export to Excel" ajax="false">
                        <p:dataExporter type="xlsx" target="caId" fileName="Characteristics Scorecard"/>
                    </p:commandButton>
                </div>
            </f:facet>



            <p:column headerText="Bin Distribution" filterBy="#{characteristicsAnalysis.binDistribution}"
                      footerText="Use LT: OR GT: Default MIN" filterFunction="#{characteristicsAnalysisBean.filterByArithmetic}">
                <h:outputText value="#{characteristicsAnalysis.binDistribution}">
                    <f:convertNumber minFractionDigits="2" />
                </h:outputText>
            </p:column>
        </p:dataTable>
    </h:form>
</h:body>
</html>

Bean
    package com.data.central.bean;

//import com.model.mgmt.exception.BusinessServiceException;
//import com.model.mgmt.model.projecttracker.ProjectTracker;
//import com.model.mgmt.service.ProjectTrackerService;
//import com.model.mgmt.utils.MessageRender;
//import org.apache.poi.ss.usermodel.*;
//import org.apache.poi.xssf.usermodel.*;

import com.data.central.model.CharacteristicsAnalysis;
import com.data.central.service.CharacteristicsAnalysisService;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.event.RowEditEvent;
import org.primefaces.event.ToggleEvent;
import org.primefaces.model.SortMeta;
import org.primefaces.model.UploadedFile;
import org.primefaces.model.Visibility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
 * Created by h on 07-02-2017.
 */
@Component
@ManagedBean
//@ViewScoped
@Scope("view")
public class CharacteristicsAnalysisBean implements Serializable {

    private CharacteristicsAnalysisService characteristicsAnalysisService;

    //@Autowired
    //private ProjectTrackerService projectTrackerService;

    private CharacteristicsAnalysis characteristicsAnalysis;
    private List<CharacteristicsAnalysis> characteristicsAnalysisList = null;
    private String actionType = "V";
    private List<CharacteristicsAnalysis> filteredCA;
    //private List<ProjectTracker> projectList = null;
    //private ProjectTracker project = null;
    private List<Boolean> list;
    private List<CharacteristicsAnalysis> analysisList;
    private UploadedFile uploadedFile;
    private String importFile;
    private File importedFile;
    private Integer projectId;
    private List<CharacteristicsAnalysis> projectList;

    //Sorting of variable_bin, variable_name and project_phase
    private List<SortMeta> preSortOrder;

    @Autowired
    public CharacteristicsAnalysisBean(CharacteristicsAnalysisService characteristicsAnalysisService) {
        this.characteristicsAnalysisService = characteristicsAnalysisService;
    }

    public List<CharacteristicsAnalysis> getFilteredCA() {
        return filteredCA;
    }

    public void setFilteredCA(List<CharacteristicsAnalysis> filteredCA) {
        this.filteredCA = filteredCA;
    }

    public CharacteristicsAnalysisService getCharacteristicsAnalysisService() {
        return characteristicsAnalysisService;
    }

    public void setCharacteristicsAnalysisService(CharacteristicsAnalysisService characteristicsAnalysisService) {
        this.characteristicsAnalysisService = characteristicsAnalysisService;
    }

    public List<CharacteristicsAnalysis> getCharacteristicsAnalysisList() {
        return characteristicsAnalysisList;
    }

    public void setCharacteristicsAnalysisList(List<CharacteristicsAnalysis> characteristicsAnalysisList) {
        this.characteristicsAnalysisList = characteristicsAnalysisList;
    }

    public CharacteristicsAnalysis getCharacteristicsAnalysis() {
        return characteristicsAnalysis;
    }

    public void setCharacteristicsAnalysis(CharacteristicsAnalysis characteristicsAnalysis) {
        this.characteristicsAnalysis = characteristicsAnalysis;
    }

    public String getActionType() {
        return actionType;
    }

    public void setActionType(String actionType) {
        this.actionType = actionType;
    }



    public List<Boolean> getList() {
        return list;
    }

    public void setList(List<Boolean> list) {
        this.list = list;
    }

    public List<CharacteristicsAnalysis> getAnalysisList() {
        return analysisList;
    }

    public void setAnalysisList(List<CharacteristicsAnalysis> analysisList) {
        this.analysisList = analysisList;
    }

    public String getImportFile() {
        return importFile;
    }

    public void setImportFile(String importFile) {
        this.importFile = importFile;
    }

    public File getImportedFile() {
        return importedFile;
    }

    public void setImportedFile(File importedFile) {
        this.importedFile = importedFile;
    }

    public UploadedFile getUploadedFile() {
        return uploadedFile;
    }

    public void setUploadedFile(UploadedFile uploadedFile) {
        this.uploadedFile = uploadedFile;
    }

    public List<SortMeta> getPreSortOrder() {
        return preSortOrder;
    }

    public void setPreSortOrder(List<SortMeta> preSortOrder) {
        this.preSortOrder = preSortOrder;
    }

    public Integer getProjectId() {
        return projectId;
    }

    public void setProjectId(Integer projectId) {
        this.projectId = projectId;
    }

    public List<CharacteristicsAnalysis> getProjectList() {
        return projectList;
    }

    public void setProjectList(List<CharacteristicsAnalysis> projectList) {
        this.projectList = projectList;
    }

    @PostConstruct
    private void init() {
        getAllCharacteristicAnalysis();
        list = Arrays.asList(true, true, true, true, true, true, true, true, true, true, true, true, true);
        preSortOrder = new ArrayList<>();
    }

    public void getAllCharacteristicAnalysis() {
        try {
            characteristicsAnalysisList = characteristicsAnalysisService.getAllCharacteristicsAnalysis();
            //  filteredCA = characteristicsAnalysisList;
        } catch (Exception e) {
          e.printStackTrace();
        }
    }


    public boolean filterByArithmetic(Object value, Object filter, Locale locale) {
        String filterText = (filter == null) ? null : filter.toString().trim();
        //Regex to check for numbers
        String regex = "\\d+";
        //Code for blank value, also whn user enters a value and changes it to blank
        if(filterText == null||filterText.equals("")) {
            return true;
        }

        if(value == null) {
            return false;
        }

        //Assumption - characters before the semi colon will determine which function to execute
        // for now filtertext length will be 3 including the semi colon
        if((filterText.matches("(LT|GT).*")) & (filterText.contains(":"))& (filterText.length()>3))
        {
            //Find out which command to execute
            String sFunction = filterText.substring(0,filterText.indexOf(":"));
            //Separate the numeric part from command
            filterText = filterText.substring(filterText.indexOf(":")+1, filterText.length());

            //Parsing value and filterText to Integer
            Double iValue = (double) value;
            Double iFilter = Double.parseDouble(filterText);

            //Logic for less than
            if(sFunction.equalsIgnoreCase("LT"))
            {
                //System.out.println("Filter Text LT"+filterText);
                //System.out.println("Value "+value);
                return (iValue.compareTo(iFilter)) <0;
            }

            //Logic for greater than
            if(sFunction.equalsIgnoreCase("GT"))
            {
                //System.out.println("Filter Text GT"+filterText);
                return (iValue.compareTo(iFilter)) >0;
            }

        }else if(filterText.matches(regex)){
            //System.out.println ("Here");
            return ((Comparable) value).compareTo(Double.valueOf(filterText)) > 0;
        }
        return false;
    }


}

堆栈跟踪 -

   java.lang.IllegalArgumentException: Cannot convert true of type class java.lang.Boolean to class java.lang.Integer
    at com.sun.el.lang.ELSupport.coerceToNumber(ELSupport.java:247) ~[el-ri-1.0.jar:na]
    at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:305) ~[el-ri-1.0.jar:na]
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276) ~[el-ri-1.0.jar:na]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) ~[jsf-impl-2.2.14.jar:2.2.14]
    at org.primefaces.component.datatable.feature.FilterFeature.filter(FilterFeature.java:192) ~[primefaces-6.1.jar:6.1]
    at org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:125) ~[primefaces-6.1.jar:6.1]
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:85) ~[primefaces-6.1.jar:6.1]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920) ~[jsf-api-2.2.14.jar:2.2]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) ~[jsf-api-2.2.14.jar:2.2]
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582) ~[jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) ~[jsf-impl-2.2.14.jar:2.2.14]
    at org.primefaces.component.api.UIData.visitTree(UIData.java:827) ~[primefaces-6.1.jar:6.1]
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[jsf-api-2.2.14.jar:2.2]
    at javax.faces.component.UIForm.visitTree(UIForm.java:371) ~[jsf-api-2.2.14.jar:2.2]
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[jsf-api-2.2.14.jar:2.2]
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) ~[jsf-api-2.2.14.jar:2.2]
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403) ~[jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322) ~[jsf-impl-2.2.14.jar:2.2.14]
    at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57) ~[primefaces-6.1.jar:6.1]
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004) ~[jsf-api-2.2.14.jar:2.2]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) ~[jsf-api-2.2.14.jar:2.2]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:432) ~[jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134) [jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.14.jar:2.2.14]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.14.jar:2.2.14]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) [jsf-api-2.2.14.jar:2.2]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) [spring-boot-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:110) [spring-boot-actuator-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:106) [spring-boot-actuator-1.5.6.RELEASE.jar:1.5.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.16.jar:8.5.16]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]

到目前为止,我的数据表中只有一个字段。

0 个答案:

没有答案