<style type="text/css">
.ui-row-editor .ui-row-editor-pencil {
margin-left:8px;
}
.ui-editable-column .ui-cell-editor-input {
overflow: hidden;
}
.ui-editable-column .ui-cell-editor-input * {
box-sizing: border-box;
}
</style>
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
<p:treeTable value="#{ttEditView.root}" editable="true" var="document" style="margin-bottom:20px">
<f:facet name="header">
Row Editing
</f:facet>
<p:ajax event="rowEdit" listener="#{ttEditView.onRowEdit}" update=":form:msgs" />
<p:ajax event="rowEditCancel" listener="#{ttEditView.onRowCancel}" update=":form:msgs" />
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{document.name}" /></f:facet>
<f:facet name="input"><p:inputText value="#{document.name}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Size">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{document.size}" /></f:facet>
<f:facet name="input"><p:inputText value="#{document.size}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{document.type}" /></f:facet>
<f:facet name="input"><p:inputText value="#{document.type}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:treeTable>
<p:treeTable value="#{ttEditView.root2}" editable="true" editMode="cell" var="document">
<f:facet name="header">
Cell Editing
</f:facet>
<p:ajax event="cellEdit" listener="#{ttEditView.onCellEdit}" update=":form:msgs" />
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{document.name}" /></f:facet>
<f:facet name="input"><p:inputText value="#{document.name}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Size">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{document.size}" /></f:facet>
<f:facet name="input"><p:inputText value="#{document.size}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{document.type}" /></f:facet>
<f:facet name="input"><p:inputText value="#{document.type}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
</p:treeTable>
</h:form>@Named("ttEditView")
@ViewScoped
public class EditView implements Serializable{
private TreeNode root;
private TreeNode root2;
@Inject
private DocumentService service;
@PostConstruct
public void init() {
root = service.createDocuments();
root2 = service.createDocuments();
}
public TreeNode getRoot() {
return root;
}
public TreeNode getRoot2() {
return root2;
}
public void setService(DocumentService service) {
this.service = service;
}
public void onRowEdit(RowEditEvent<TreeNode> event) {
FacesMessage msg = new FacesMessage("Document Edited", event.getObject().toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowCancel(RowEditEvent<TreeNode> event) {
FacesMessage msg = new FacesMessage("Edit Cancelled", event.getObject().toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}@Named
@ApplicationScoped
public class DocumentService {
public TreeNode createDocuments() {
TreeNode root = new DefaultTreeNode(new Document("Files", "-", "Folder"), null);
TreeNode documents = new DefaultTreeNode(new Document("Documents", "-", "Folder"), root);
TreeNode pictures = new DefaultTreeNode(new Document("Pictures", "-", "Folder"), root);
TreeNode movies = new DefaultTreeNode(new Document("Movies", "-", "Folder"), root);
TreeNode work = new DefaultTreeNode(new Document("Work", "-", "Folder"), documents);
TreeNode primefaces = new DefaultTreeNode(new Document("PrimeFaces", "-", "Folder"), documents);
//Documents
TreeNode expenses = new DefaultTreeNode("document", new Document("Expenses.doc", "30 KB", "Word Document"), work);
TreeNode resume = new DefaultTreeNode("document", new Document("Resume.doc", "10 KB", "Word Document"), work);
TreeNode refdoc = new DefaultTreeNode("document", new Document("RefDoc.pages", "40 KB", "Pages Document"), primefaces);
//Pictures
TreeNode barca = new DefaultTreeNode("picture", new Document("barcelona.jpg", "30 KB", "JPEG Image"), pictures);
TreeNode primelogo = new DefaultTreeNode("picture", new Document("logo.jpg", "45 KB", "JPEG Image"), pictures);
TreeNode optimus = new DefaultTreeNode("picture", new Document("optimusprime.png", "96 KB", "PNG Image"), pictures);
//Movies
TreeNode pacino = new DefaultTreeNode(new Document("Al Pacino", "-", "Folder"), movies);
TreeNode deniro = new DefaultTreeNode(new Document("Robert De Niro", "-", "Folder"), movies);
TreeNode scarface = new DefaultTreeNode("mp3", new Document("Scarface", "15 GB", "Movie File"), pacino);
TreeNode carlitosWay = new DefaultTreeNode("mp3", new Document("Carlitos' Way", "24 GB", "Movie File"), pacino);
TreeNode goodfellas = new DefaultTreeNode("mp3", new Document("Goodfellas", "23 GB", "Movie File"), deniro);
TreeNode untouchables = new DefaultTreeNode("mp3", new Document("Untouchables", "17 GB", "Movie File"), deniro);
return root;
}
public TreeNode createCheckboxDocuments() {
TreeNode root = new CheckboxTreeNode(new Document("Files", "-", "Folder"), null);
TreeNode documents = new CheckboxTreeNode(new Document("Documents", "-", "Folder"), root);
TreeNode pictures = new CheckboxTreeNode(new Document("Pictures", "-", "Folder"), root);
TreeNode movies = new CheckboxTreeNode(new Document("Movies", "-", "Folder"), root);
TreeNode work = new CheckboxTreeNode(new Document("Work", "-", "Folder"), documents);
TreeNode primefaces = new CheckboxTreeNode(new Document("PrimeFaces", "-", "Folder"), documents);
//Documents
TreeNode expenses = new CheckboxTreeNode("document", new Document("Expenses.doc", "30 KB", "Word Document"), work);
TreeNode resume = new CheckboxTreeNode("document", new Document("Resume.doc", "10 KB", "Word Document"), work);
TreeNode refdoc = new CheckboxTreeNode("document", new Document("RefDoc.pages", "40 KB", "Pages Document"), primefaces);
//Pictures
TreeNode barca = new CheckboxTreeNode("picture", new Document("barcelona.jpg", "30 KB", "JPEG Image"), pictures);
TreeNode primelogo = new CheckboxTreeNode("picture", new Document("logo.jpg", "45 KB", "JPEG Image"), pictures);
TreeNode optimus = new CheckboxTreeNode("picture", new Document("optimusprime.png", "96 KB", "PNG Image"), pictures);
//Movies
TreeNode pacino = new CheckboxTreeNode(new Document("Al Pacino", "-", "Folder"), movies);
TreeNode deniro = new CheckboxTreeNode(new Document("Robert De Niro", "-", "Folder"), movies);
TreeNode scarface = new CheckboxTreeNode("mp3", new Document("Scarface", "15 GB", "Movie File"), pacino);
TreeNode carlitosWay = new CheckboxTreeNode("mp3", new Document("Carlitos' Way", "24 GB", "Movie File"), pacino);
TreeNode goodfellas = new CheckboxTreeNode("mp3", new Document("Goodfellas", "23 GB", "Movie File"), deniro);
TreeNode untouchables = new CheckboxTreeNode("mp3", new Document("Untouchables", "17 GB", "Movie File"), deniro);
return root;
}
}