title: JSF Tree Validation Form on change node
body: <p>I have a class Document for create a Tree with a list of document objects.</p>
  
  <pre><code>public class Document implements Serializable {
  
       private String name;
  
       private String size;
       private List&lt;Field&gt; fields;
  
       public Document(String name, String size, String type) {
          this.name = name;
          this.size = size;
       }
  
       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 List&lt;Field&gt; getFields() {
         return fields;
      }
  
      public void setFields(List&lt;Field&gt; fields) {
       this.fields = fields;
    }
  }  
  </code></pre>
  
  <p>Also I have a  Field class  for store relevant information in documents</p>
  
  <pre><code>public class Field implements Serializable {
  private int fieldIndex;
  private String label;
  private String value;
  
  private List&lt;Values&gt; list;
  
  public Field() {
  }
  
  public int getFieldIndex() {
      return fieldIndex;
  }
  
  public void setFieldIndex(int fieldIndex) {
      this.fieldIndex = fieldIndex;
  }
  
  public Field(String label) {
      this.label = label;
  }
  
  public String getLabel() {
      return label;
  }
  
  public void setLabel(String label) {
      this.label = label;
  }
  
  public String getValue() {
      return value;
  }
  
  public void setValue(String value) {
      this.value = value;
  }
  
  
  public List&lt;Values&gt; getList() {
      return list;
  }
  
  
  public void setList(List&lt;Values&gt; list) {
      this.list = list;
  }
  } 
  </code></pre>
  
  <p>My ManagedBean create a tree with some documents and store some data for each document. When i select the tree node, it's show a dynamic form with every field and inputs for enter some value.</p>
  
  <pre><code>@ManagedBean(name="treeSelectionView")
  @ViewScoped
  public class SelectionView implements Serializable {
  
  private TreeNode root1;
  
  private TreeNode selectedNode;
  private String email;
  
  private List&lt;Field&gt; fields;
  
  public String getEmail() {
  return email;
  }
  
  public void setEmail(String email) {
  this.email = email;
  }
  
  @PostConstruct
  public void init() {
  
      TreeNode root = new DefaultTreeNode(new Document("Files", "-", "Folder"), null);
  
      TreeNode documents = new DefaultTreeNode(new Document("Documents", "-", "Folder"), root);
  
      Field f1=new Field();
      Field f2=new Field();
      Field f3=new Field();
  
      f1.setLabel("email");
      f1.setValue("");
  
      f2.setLabel("doc");
      f2.setValue("");
  
      f3.setLabel("otro");
      f3.setValue("");
  
      List&lt;Field&gt; fields=new ArrayList&lt;Field&gt;();
      fields.add(f1);
      fields.add(f2);
      fields.add(f3);        
  
      List&lt;Field&gt; fields1=new ArrayList&lt;Field&gt;();
      f1=new Field();
      f2=new Field();
      f3=new Field();
  
      f1.setLabel("email");
      f1.setValue("");
  
      f2.setLabel("doc");
      f2.setValue("");
  
      f3.setLabel("otro");
      f3.setValue("");
  
      fields1.add(f1);
      fields1.add(f2);
      fields1.add(f3); 
  
      List&lt;Field&gt; fields2=new ArrayList&lt;Field&gt;();
  
      f1=new Field();
      f2=new Field();
      f3=new Field();
  
      f1.setLabel("email");
      f1.setValue("");
  
      f2.setLabel("doc");
      f2.setValue("");
  
      f3.setLabel("otro");
      f3.setValue("");
  
      fields2.add(f1);
      fields2.add(f2);
      fields2.add(f3);        
  
  
      //Documents
      Document d1= new Document("Expenses.doc", "30 KB", "Word Document");
      Document d2=new Document("Resume.doc", "10 KB", "Word Document");
      Document d3=new Document("RefDoc.pages", "40 KB", "Pages Document");
  
      d1.setFields(fields);
      d2.setFields(fields1);
      d3.setFields(fields2);
  
  
      TreeNode expenses = new DefaultTreeNode("document",d1, documents);
      TreeNode resume = new DefaultTreeNode("document", d2, documents);
      TreeNode refdoc = new DefaultTreeNode("document",d3 , documents);
      documents.setExpanded(true);
      root1 = root;
      root1.setExpanded(true);
  }
  
  
  public void onNodeDocumentSelect(NodeSelectEvent nodeSelected) {
  //  fields=((Document)nodeSelected.getTreeNode().getData()).getFields();
      fields=((Document)selectedNode.getData()).getFields();
  }
  
  public TreeNode getRoot1() {
      return root1;
  }
  
  public TreeNode getSelectedNode() {
      return selectedNode;
  }
  
  public void setSelectedNode(TreeNode selectedNode) {
      this.selectedNode = selectedNode;
  }
  
  public List&lt;Field&gt; getFields() {
      return fields;
  }
  
  public void setFields(List&lt;Field&gt; fields) {
      this.fields = fields;
  }
  }
  </code></pre>
  
  <p>My JSF looks like </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"&gt;
  &lt;h:head&gt;
  &lt;title&gt;Default title&lt;/title&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
  &lt;h:panelGrid columns="2"&gt;
  &lt;h:form id="treeForm"&gt;
     &lt;p:panel id="panel22" header="Documents" style="height:400px"&gt;
          &lt;p:growl id="msgs" showDetail="true" /&gt;
          &lt;p:tree value="#{treeSelectionView.root1}" var="doc" selectionMode="single"  selection="#{treeSelectionView.selectedNode}" &gt;
              &lt;p:ajax process="@this"   event="select"  update=":myForm:dymanicForm"  listener="#{treeSelectionView.onNodeDocumentSelect}" /&gt;    
              &lt;p:treeNode   expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed"&gt;
                  &lt;h:outputText value="#{doc.name}"/&gt;
              &lt;/p:treeNode&gt;
              &lt;p:treeNode type="document" icon="ui-icon-document" &gt;
                  &lt;h:outputText value="#{doc.name}" /&gt;
              &lt;/p:treeNode&gt;
  
          &lt;/p:tree&gt;
     &lt;/p:panel&gt;
  &lt;/h:form&gt;
  &lt;h:form id="myForm"&gt;
  &lt;p:panel id="panel222" header="Info Doccs" style="height:400px"&gt;
  
      &lt;p:panel id="dymanicForm" &gt;     
          &lt;ui:repeat value="#{treeSelectionView.fields}" var="componentMetadata"&gt;
              &lt;h:panelGrid  columns="3"&gt;
                 &lt;h:outputText value="#{componentMetadata.label}"/&gt;:
                &lt;h:inputText id="field" value="#{componentMetadata.value}" 
                   required="true" label="#{componentMetadata.label}"/&gt;
              &lt;h:message for="field" style="color:red" /&gt;&lt;/h:panelGrid&gt;
          &lt;/ui:repeat&gt;
      &lt;/p:panel&gt;
      &lt;h:commandButton value="Submit" action="result" /&gt;
    &lt;/p:panel&gt;
     &lt;/h:form&gt;
  &lt;/h:panelGrid&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I press the submit button the values are submitted and store in each field, also  the validations are fired. But I really need remove the submit button and  validate the form when i lost focus every node. By example if i am in the first node validate the form only when i lost focus , but if the form validation fail i need to stay in this node.</p>
  
  <p>Really I appreciate any help you can give me.
  Thanks a lot in advance.</p>