У меня есть программный Dynamic TreeTable, который создается и добавляется на панель форм.Эта проблема воспроизводима только в Мохарре.
Код работает только с
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
или
<context-param>
<param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name>
<param-value>/treetableprogram.xhtml</param-value>
</context-param>
Минимальное, Полное и Проверяемое - простые лица 6.2, jsf 2.3.3 https://github.com/ravihariharan/primefaces-test-treetable.git
treetableprogram.xhtml, BasicView1.java
На основе примера демонстрации PrimeFaces: https://www.primefaces.org/showcase/ui/data/treetable/basic.xhtml
@PostConstruct
public void init() {
root = service.createDocuments();
TreeTable table = new TreeTable();
table.setId("treeTableId");
table.setVar("document");
table.setValueExpression("value", createValueExpression("#{ttBasicView1.root}", TreeNode.class));
Column column = new Column();
column.setId("col1");
OutputLabel label = new OutputLabel();
label.setId("ol1");
label.setValueExpression("value", createValueExpression("#{document.name}", String.class));
column.getChildren().add(label);
table.getChildren().add(column);
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = context.getViewRoot();
viewRoot.findComponent("form:mainPanel").getChildren().add(table);
}
Проблема
- TreeTable не может быть развернут или свернут после начальной загрузки.
- Код работает только с javax.faces.PARTIAL_STATE_SAVING false в Mojarra, что не является идеальным случаем.
- Предупреждающее сообщение при щелчке по развернутому 11 июня 2018 15:13:29 com.sun.faces.application.view.FaceletPartialStateManagementStrategy saveDynamicActions ПРЕДУПРЕЖДЕНИЕ: невозможно сохранить динамическое действие с формой clientId ': treeTableId: col1', поскольку UIComponent не можетбыть найден 11 июня 2018 15:13:29 com.sun.faces.application.view.FaceletPartialStateManagementStrategy saveDynamicActions ПРЕДУПРЕЖДЕНИЕ: невозможно сохранить динамическое действие с формой clientId ': treeTableId: ol1 ', поскольку UIComponent не может быть найден
Ссылочный URL: JSF Сохранение состояния и пользовательские компоненты с динамически добавляемыми дочерними элементами
Проблема не возникаетна реализацию MyFaces.https://github.com/ravihariharan/primefaces-test-myfaces.git
Я не уверен, что это проблема частичного сохранения состояния Mojarra или ошибка из-за PrimeFaces.
BasicView1.java
package org.primefaces.showcase.view.data.treetable;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.el.ValueExpression;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.primefaces.component.column.Column;
import org.primefaces.component.outputlabel.OutputLabel;
import org.primefaces.component.treetable.TreeTable;
import org.primefaces.model.TreeNode;
import org.primefaces.showcase.domain.Document;
import org.primefaces.showcase.service.DocumentService;
@ManagedBean(name = "ttBasicView1")
@ViewScoped
public class BasicView1 implements Serializable {
private String testString = "";
private TreeNode root;
private Document selectedDocument;
@ManagedProperty("#{documentService}")
private DocumentService service;
@PostConstruct
public void init() {
root = service.createDocuments();
TreeTable table = new TreeTable();
table.setId("treeTableId");
table.setVar("document");
table.setValueExpression("value", createValueExpression("#{ttBasicView1.root}", TreeNode.class));
Column column = new Column();
column.setId("col1");
OutputLabel label = new OutputLabel();
label.setId("ol1");
label.setValueExpression("value", createValueExpression("#{document.name}", String.class));
column.getChildren().add(label);
table.getChildren().add(column);
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = context.getViewRoot();
viewRoot.findComponent("form:mainPanel").getChildren().add(table);
}
public TreeNode getRoot() {
return root;
}
public void setService(DocumentService service) {
this.service = service;
}
public Document getSelectedDocument() {
return selectedDocument;
}
public void setSelectedDocument(Document selectedDocument) {
this.selectedDocument = selectedDocument;
}
public static ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(),
valueExpression, valueType);
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
}
Document.java
package org.primefaces.showcase.domain;
import java.io.Serializable;
public class Document implements Serializable, Comparable<Document> {
private String name;
private String size;
private String type;
public Document(String name, String size, String type) {
this.name = name;
this.size = size;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
//Eclipse Generated hashCode and equals
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Document other = (Document) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (size == null) {
if (other.size != null)
return false;
} else if (!size.equals(other.size))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return name;
}
public int compareTo(Document document) {
return this.getName().compareTo(document.getName());
}
}
treetableprogram.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>PrimeFaces Test</title>
</h:head>
<h:body>
<h1>#{ttBasicView1.testString}</h1>
<h:form id="form">
<p:panel id="mainPanel" header="">
</p:panel>
</h:form>
</h:body>
</html>