启用行虚拟化的表上primefaces 8.0中的筛选器错误

wvyml7n5  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(571)

我正在使用PrimeFaces8.0。包含冻结列的表,以及冻结部分和滚动部分中列的筛选器。行虚拟化已启用。
按钮代码:

  1. <p:commandLink partialSubmit="true" process="@this" action="#{controller.loadCars}" update=":form:tab1">
  2. <h:outputText value="Submit"/>
  3. </p:commandLink>

表代码:

  1. <h:form id="form">
  2. <p:dataTable
  3. id="tab1"
  4. scrollable="true"
  5. scrollHeight="350"
  6. scrollWidth="900"
  7. frozenColumns="2"
  8. var="car"
  9. scrollRows="5"
  10. virtualScroll="true"
  11. lazy="true"
  12. rows="5"
  13. rowIndexVar="#"
  14. value="#{model.cars}"
  15. widgetVar="carsTable"
  16. emptyMessage="No cars found with given criteria"
  17. filteredValue="#{model.filteredCars}">
  18. <p:ajax event="filter" />
  19. <p:columnGroup groupRow="true" type="frozenHeader" >
  20. <p:row>
  21. <p:column field="1" headerText="Id" filterBy="#{car.id}" filterMatchMode="contains" >
  22. <p:inputText style="width:90%;"
  23. onchange="PF('carsTable').filter()"
  24. onkeyup="PF('carsTable').filter()"
  25. onkeypress="if (event.keyCode == 13) { return false; }">
  26. </p:inputText>
  27. </p:column>
  28. <p:column field="2" headerText="Color" filterBy="#{car.color}" filterMatchMode="contains" >
  29. <p:inputText style="width:90%;"
  30. onchange="PF('carsTable').filter()"
  31. onkeyup="PF('carsTable').filter()"
  32. onkeypress="if (event.keyCode == 13) { return false; }">
  33. </p:inputText>
  34. </p:column>
  35. </p:row>
  36. </p:columnGroup>
  37. <p:columnGroup groupRow="true" type="scrollableHeader">
  38. <p:row>
  39. <p:column headerText="Id" width="100"/>
  40. <p:column field="4" headerText="Year" filterBy="#{car.year}" filterable="true" filterMatchMode="contains" width="100">
  41. <p:inputText style="width:90%;"
  42. onchange="PF('carsTable').filter()"
  43. onkeyup="PF('carsTable').filter()"
  44. onkeypress="if (event.keyCode == 13) { return false; }">
  45. </p:inputText>
  46. </p:column>
  47. <p:column headerText="Brand" width="100"/>
  48. <p:column headerText="Color" width="100"/>
  49. <p:column headerText="Id" width="100"/>
  50. <p:column headerText="Year" width="100"/>
  51. <p:column headerText="Brand" width="100"/>
  52. <p:column headerText="Color" width="100"/>
  53. <p:column headerText="Id" width="100"/>
  54. <p:column headerText="Year" width="100"/>
  55. <p:column headerText="Brand" width="100"/>
  56. <p:column field="3" sortBy="#{car.color}" filterBy="#{car.color}" headerText="Color2" filterMatchMode="contains" width="100" >
  57. <p:inputText style="width:90%;"
  58. onchange="PF('carsTable').filter()"
  59. onkeyup="PF('carsTable').filter()"
  60. onkeypress="if (event.keyCode == 13) { return false; }">
  61. </p:inputText>
  62. </p:column>
  63. </p:row>
  64. </p:columnGroup>
  65. <p:column headerText="Id" >
  66. <h:outputText value="#{car.id}"/>
  67. </p:column>
  68. <p:column headerText="Color" >
  69. <h:outputText value="#{car.color}" />
  70. </p:column>
  71. <p:column headerText="Id">
  72. <h:outputText value="#{car.id}" />
  73. </p:column>
  74. <p:column headerText="Year">
  75. <h:outputText value="#{car.year}" />
  76. </p:column>
  77. <p:column headerText="Brand">
  78. <h:outputText value="#{car.brand}" />
  79. </p:column>
  80. <p:column headerText="Color">
  81. <h:outputText value="#{car.color}" />
  82. </p:column>
  83. <p:column headerText="Id">
  84. <h:outputText value="#{car.id}" />
  85. </p:column>
  86. <p:column headerText="Year">
  87. <h:outputText value="#{car.year}" />
  88. </p:column>
  89. <p:column headerText="Brand">
  90. <h:outputText value="#{car.brand}" />
  91. </p:column>
  92. <p:column headerText="Color">
  93. <h:outputText value="#{car.color}" />
  94. </p:column>
  95. <p:column headerText="Id">
  96. <h:outputText value="#{car.id}" />
  97. </p:column>
  98. <p:column headerText="Year">
  99. <h:outputText value="#{car.year}" />
  100. </p:column>
  101. <p:column headerText="Brand">
  102. <h:outputText value="#{car.brand}" />
  103. </p:column>
  104. <p:column headerText="Color">
  105. <h:outputText value="#{car.color}" />
  106. </p:column>
  107. <p:column groupRow="true" headerText="Color2" >
  108. <h:outputText value="#{car.color}" />
  109. </p:column>
  110. </p:dataTable>
  111. </h:form>

控制器

  1. import javax.enterprise.context.RequestScoped;
  2. import javax.inject.Named;
  3. @Named
  4. @RequestScoped
  5. public class Controller implements Serializable {
  6. @Inject
  7. private Model model;
  8. public void loadCars(){
  9. model.getCars().clear();
  10. List<Car> tempCars = new ArrayList<>();
  11. for(int i = 0 ; i < 100 ; i++) {
  12. tempCars.add(new Car( UUID.randomUUID().toString().substring(0, 8), model.getBrands().get((int)(Math.random() * 10)), String.valueOf((int)(Math.random() * 50 + 1960)), model.getColors().get((int) (Math.random() * 10)), (int) (Math.random() * 100000), (Math.random() > 0.5) ? true: false ));
  13. }
  14. model.getCars().addAll(tempCars);
  15. }
  16. }

模型

  1. import javax.enterprise.context.SessionScoped;
  2. import javax.inject.Named;
  3. import java.io.Serializable;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import lombok.Data;
  7. @Named
  8. @SessionScoped
  9. @Data
  10. public class Model implements Serializable {
  11. Model(){
  12. colors = new ArrayList<>();
  13. colors.add("Black");
  14. colors.add("White");
  15. colors.add("Green");
  16. colors.add("Red");
  17. colors.add("Blue");
  18. colors.add("Orange");
  19. colors.add("Silver");
  20. colors.add("Yellow");
  21. colors.add("Brown");
  22. colors.add("Maroon");
  23. brands = new ArrayList<>();
  24. brands.add("BMW");
  25. brands.add("Mercedes");
  26. brands.add("Volvo");
  27. brands.add("Audi");
  28. brands.add("Renault");
  29. brands.add("Fiat");
  30. brands.add("Volkswagen");
  31. brands.add("Honda");
  32. brands.add("Jaguar");
  33. brands.add("Ford");
  34. }
  35. private List<Car> cars = new ArrayList<>();
  36. private List<Car> filteredCars;
  37. private List<String> colors;
  38. private List<String> brands;
  39. }

对象

  1. public class Car implements Serializable {
  2. public String id;
  3. public String brand;
  4. public String year;
  5. public String color;
  6. public int price;
  7. public boolean sold;
  8. public Car() {}
  9. public Car(String id, String brand, String year, String color) {
  10. this.id = id;
  11. this.brand = brand;
  12. this.year = year;
  13. this.color = color;
  14. }
  15. public Car(String id, String brand, String year, String color, int price, boolean sold) {
  16. this.id = id;
  17. this.brand = brand;
  18. this.year = year;
  19. this.color = color;
  20. this.price = price;
  21. this.sold = sold;
  22. }
  23. public String getId() {
  24. return id;
  25. }
  26. public void setId(String id) {
  27. this.id = id;
  28. }
  29. public String getBrand() {
  30. return brand;
  31. }
  32. public void setBrand(String brand) {
  33. this.brand = brand;
  34. }
  35. public String getYear() {
  36. return year;
  37. }
  38. public void setYear(String year) {
  39. this.year = year;
  40. }
  41. public String getColor() {
  42. return color;
  43. }
  44. public void setColor(String color) {
  45. this.color = color;
  46. }
  47. public int getPrice() {
  48. return price;
  49. }
  50. public void setPrice(int price) {
  51. this.price = price;
  52. }
  53. public boolean isSold() {
  54. return sold;
  55. }
  56. public void setSold(boolean sold) {
  57. this.sold = sold;
  58. }
  59. @Override
  60. public int hashCode() {
  61. int hash = 7;
  62. hash = 59 * hash + (this.id != null ? this.id.hashCode() : 0);
  63. return hash;
  64. }
  65. @Override
  66. public boolean equals(Object obj) {
  67. if (obj == null) {
  68. return false;
  69. }
  70. if (getClass() != obj.getClass()) {
  71. return false;
  72. }
  73. final Car other = (Car) obj;
  74. if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
  75. return false;
  76. }
  77. return true;
  78. }
  79. }

如果关闭行虚拟化,那么表中的过滤器都可以。
将数据筛选到表中时发生primefaces库的js错误。

  1. Uncaught TypeError: can't access property "children", b.bodyTable is undefined
  2. oncomplete http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  3. v http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  4. jQuery 6
  5. send http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  6. offer http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  7. handle http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  8. ab http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  9. filter http://localhost:8080/jsf_html4+PR8/ line 2 > injectedScript:1
  10. callBehavior http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:22
  11. filter http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  12. filterTimeout http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  13. setTimeout handler*bindFilterEvent/< http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  14. jQuery 2
  15. components.js.xhtml:12:31834
  16. oncomplete http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  17. v http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  18. jQuery 6
  19. send http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  20. offer http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  21. handle http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  22. ab http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:18
  23. filter http://localhost:8080/jsf_html4+PR8/ line 2 > injectedScript:1
  24. callBehavior http://localhost:8080/jsf_html4+PR8/javax.faces.resource/core.js.xhtml?ln=primefaces&v=8.0:22
  25. filter http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  26. filterTimeout http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  27. (Асинхронный: setTimeout handler)
  28. bindFilterEvent http://localhost:8080/jsf_html4+PR8/javax.faces.resource/components.js.xhtml?ln=primefaces&v=8.0:12
  29. jQuery 2

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题