2
votes

I need your help.There is a strange error in my project. I have a primefaces dataTable in my xhtml and its column's sortBy attribute does not work. sortBy seems null in BeanPropertyComparator class when I debugged my code. The tomcat's error log is written below;

Apache Tomcat 7.0.52 Log

java.lang.IllegalStateException: CDATA tags may not nest
    at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:681)
    at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:179)
    at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:341)
    at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:109)
    at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:202)
    at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:126)
    at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)




Apache Tomcat 7.0.52

javax.faces.FacesException: java.lang.NullPointerException
    at org.primefaces.model.BeanPropertyComparator.compare(BeanPropertyComparator.java:92)
    at java.util.TimSort.countRunAndMakeAscending(TimSort.java:324)
    at java.util.TimSort.sort(TimSort.java:189)
    at java.util.TimSort.sort(TimSort.java:173)
    at java.util.Arrays.sort(Arrays.java:659)
    at java.util.Collections.sort(Collections.java:217)
    at org.primefaces.component.datatable.feature.SortFeature.singleSort(SortFeature.java:148)
    at org.primefaces.component.datatable.feature.SortFeature.encode(SortFeature.java:106)
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:80)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at org.primefaces.component.api.UIData.visitTree(UIData.java:827)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:319)
    at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
    at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:425)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.NullPointerException
    at org.primefaces.model.BeanPropertyComparator.compare(BeanPropertyComparator.java:58)
    ... 48 more



When I am debugging the code, it comes BeanPropertyComparator's 'compare' method. Parameter sortBy seems to be 'null'. The class and its method is this;

public class BeanPropertyComparator implements Comparator {

    private ValueExpression sortBy;
    private boolean asc;
    private String var;
    private MethodExpression sortFunction;
    private boolean caseSensitive = false;
    private Locale locale;
    private Collator collator;
    private int nullSortOrder;

    public BeanPropertyComparator(ValueExpression sortBy, String var, SortOrder sortOrder, MethodExpression sortFunction, boolean caseSensitive, Locale locale, int nullSortOrder) {
        this.sortBy = sortBy;
        this.var = var;
        this.asc = sortOrder.equals(SortOrder.ASCENDING);
        this.sortFunction = sortFunction;
        this.caseSensitive = caseSensitive;
        this.locale = locale;
        this.collator = Collator.getInstance(locale);
        this.nullSortOrder = nullSortOrder;
    }

    @SuppressWarnings("unchecked")
    public int compare(Object obj1, Object obj2) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();

            context.getExternalContext().getRequestMap().put(var, obj1);
            Object value1 = sortBy.getValue(context.getELContext());
            context.getExternalContext().getRequestMap().put(var, obj2);
            Object value2 = sortBy.getValue(context.getELContext());

ERROR: ValueExpression sortBy becomes null

My xhtml page is below;

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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:p="http://primefaces.org/ui"
      xmlns:b="http://bootsfaces.net/ui"
      xmlns:f="http://java.sun.com/jsf/core">


    <h:head>


    </h:head>

    <h:body>

        <h:form id="formmm">

            <p:dataTable id="dt"
                         var="kullanici"
                         value="#{deneView.ortakKurumKullanicilar}"
                         rowKey="#{kullanici.id}">

                <f:facet name="header">
                    #{etiketler.baslikKullanicilar}
                </f:facet>

                <p:column headerText="#{etiketler.tcKimlikNo}"
                          sortBy="#{kullanici.tckn}">
                    <h:outputText value="#{kullanici.tckn}" />
                </p:column>

                <p:column headerText="#{etiketler.adi}"
                          sortBy="#{kullanici.adi}" >
                    <h:outputText value="#{kullanici.adi}" />
                </p:column>

                <p:column headerText="#{etiketler.soyadi}"
                          sortBy="#{kullanici.soyadi}" >
                    <h:outputText value="#{kullanici.soyadi}" />
                </p:column>

            </p:dataTable>


        </h:form>



    </h:body>

</html>


And View of my xhtml;

@ManagedBean
@ViewScoped
public class DeneView implements Serializable{

    private List<DeneDomain> ortakKurumKullanicilar;

    @PostConstruct
    public void init() {

        DeneDomain kullanici1 = new DeneDomain();
        kullanici1.setId(1L);
        kullanici1.setAdi("Ahmet");
        kullanici1.setSoyadi("Candemir");
        kullanici1.setTckn("11111111111");
        DeneDomain kullanici2 = new DeneDomain();
        kullanici2.setId(2L);
        kullanici2.setAdi("Mehmet");
        kullanici2.setSoyadi("Zahir");
        kullanici2.setTckn("34738946323");
        DeneDomain kullanici3 = new DeneDomain();
        kullanici3.setId(3L);
        kullanici3.setAdi("Cem");
        kullanici3.setSoyadi("Anil");
        kullanici3.setTckn("23567890546");
        DeneDomain kullanici4 = new DeneDomain();
        kullanici4.setId(4L);
        kullanici4.setAdi("Kazim");
        kullanici4.setSoyadi("Izit");
        kullanici4.setTckn("43256789000");
        DeneDomain kullanici5 = new DeneDomain();
        kullanici5.setId(5L);
        kullanici5.setAdi("Nami");
        kullanici5.setSoyadi("Cagan");
        kullanici5.setTckn("52546546556");
        DeneDomain kullanici6 = new DeneDomain();
        kullanici6.setId(6L);
        kullanici6.setAdi("Zeki");
        kullanici6.setSoyadi("Under");
        kullanici6.setTckn("14324324233");
        DeneDomain kullanici7 = new DeneDomain();
        kullanici7.setId(7L);
        kullanici7.setAdi("Deniz");
        kullanici7.setSoyadi("Fazli");
        kullanici7.setTckn("34454545455");

        ortakKurumKullanicilar = new ArrayList<>();
        ortakKurumKullanicilar.add(kullanici1);
        ortakKurumKullanicilar.add(kullanici2);
        ortakKurumKullanicilar.add(kullanici3);
        ortakKurumKullanicilar.add(kullanici4);
        ortakKurumKullanicilar.add(kullanici5);
        ortakKurumKullanicilar.add(kullanici6);
        ortakKurumKullanicilar.add(kullanici7);
    }

    public List<DeneDomain> getOrtakKurumKullanicilar() {
        return ortakKurumKullanicilar;
    }

    public void setOrtakKurumKullanicilar(List<DeneDomain> ortakKurumKullanicilar) {
        this.ortakKurumKullanicilar = ortakKurumKullanicilar;
    }

}

Edited

1
Please provide the code. XHTML and JSF !Makky
@Makky: Better to always ask for an minimal reproducible example. Just type [ mcve ] (without the spaces) in your commentKukeltje
@Makky : I have edited my question.bekair
What is your PF version?Kukeltje
primefaces 6.0. It works in a different web application. I have opened a new jsf project and add the same domain, xhtml and view it works fine.bekair

1 Answers

0
votes

I solved the problem. Primefaces dataTable's attribute was not working. The problem was on the sending of the ValueExpression sortBy's value from xhtml to 'compare' method of BeanPropertyComparator class of primefaces. SortBy value was coming null. I understand, the problem was not about primefaces, it was about jsf 2.2. javax.faces2.2.jar jar was added by maven repository but It was broke down. While I right clicked the dependency that was created by maven (pom.xml), selected the manually install the artifact option and changed the jar that I downloaded due to another normal (not maven) project. Now it works fine for me but another problems appeared after the solve. After filterBy, if I did not delete the entry for filtering, I could not sort the table again all the data was dissapeared until I delete the entry. I learned it is abput Serializable interface. The domain class that I put with a list to the dataTable's value attribute must implements Serializable interface. In my project there is also a WebService part and it has domain classes. I should use these classes in the Web project but it can not see the domain as Serializable altough they are Serializable.