私はあなたの助けが必要です。私のプロジェクトには奇妙なエラーがあります。私は私のxhtmlのprimefaces dataTableを持ち、その列のsortBy属性は機能しません。コードをデバッグしたときに、sortByがBeanPropertyComparatorクラスでnullに見えます。 tomcatのエラーログは以下のように書かれています。
Primefaces DataTable SortByが機能しない
のApache Tomcat 7.0.52ログ
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
私は、コードをデバッグしていた場合、それはBeanPropertyComparatorの '比較' メソッドを付属しています。パラメータsortByが 'null'のようです。 クラスとそのメソッドはこれです。
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になる ヌル
マイXHTMLページは以下の通りです。
<?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>
そして私の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;
}
}
編集
コードを入力してください。 XHTMLとJSF! – Makky
@Makky:いつも[mcve]を求めるのがよい。あなたのコメントに[mcve](スペースなし)を入力してください。 – Kukeltje
@Makky:私は自分の質問を編集しました。 – bekair