title: Update form from another form using <f: ajax> in JSF
body: <p>Good day,</p>
  
  <p>I am developing an application in java server faces 2.2.20 and mariadb 10.4 databases.
  I have a problem when updating with f: ajax to another form where I have a table that lists the products with their respective images entered, but the images returned by the method from the bean to the img in html are not displayed, although the image if it has in the src its respective route; The good content as text if it is updated correctly without reloading the page this means that if ajax works in part.
  <br></p>
  
  <hr>
  
  <p>This is the code where the product data is entered and the image is uploaded to the controller.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>                &lt;h:form id="crearCatalogos" enctype="multipart/form-data"&gt; &lt;!--prependId="false" --&gt;  
                      &lt;div class="container"&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="col-lg-5"&gt;
                                  &lt;fieldset&gt;
                                      &lt;legend&gt; Informacion:&lt;/legend&gt;
                                      &lt;h:messages style="color:red"&gt;&lt;/h:messages&gt;
                                      &lt;label&gt;Nombre de categoria: &lt;/label&gt;&lt;br/&gt;
                                      &lt;h:inputText value="#{FileUploadFormBeanRequest.nombreCatalogo}" id="primerNombre" class="inputPersonalizado" html5:placeholder="Ingrese el nombre" maxlength="20" required="true" validatorMessage="No debe superar 20 caracteres" requiredMessage="Ingrese el nombre"&gt;&lt;/h:inputText&gt;&lt;br/&gt;&lt;br/&gt;
  
                                      &lt;label&gt;Seleccionar imagen: &lt;/label&gt;&lt;br/&gt;
                                      &lt;h:inputFile id="imgInp"  value="#{FileUploadFormBeanRequest.archivoCarga}" validator="#{FileUploadFormBeanRequest.validarImagenCategoria}" class="inputPersonalizadoFile"&gt; &lt;/h:inputFile&gt;                                                                        
  
                                      &lt;br/&gt;&lt;br/&gt;
                                      &lt;h:commandButton class="btn btn-primary" value="Cargar"&gt;
                                          &lt;f:ajax render="@form : formVerCatalogos : table_verCatalogos" event="action" execute="@form"  listener="#{FileUploadFormBeanRequest.guardarDatosCategoria()}"&gt;&lt;/f:ajax&gt;
                                      &lt;/h:commandButton&gt;                                                                                    
                                  &lt;/fieldset&gt;  
                                  &lt;br/&gt;&lt;br/&gt; 
                              &lt;/div&gt; 
                              &lt;div class="col-lg-5 imgCategorias"&gt;
                                 &lt;div class="text-center"&gt;
                                     &lt;img id="noImagen54" src="../TEMPLATE/img/noImagen.jpeg" class="rounded img-thumbnail" alt="..."/&gt;  
                                     &lt;img id="imagenCategoriaFile" src="#" class="rounded img-thumbnail imagenCategoriaFile" alt="..."/&gt;  
                                 &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;    ​
                  &lt;/h:form&gt;                                                                </code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://i.stack.imgur.com/SofyV.png" rel="nofollow noreferrer">first form view</a>   <br>
  <a href="https://i.stack.imgur.com/aWvCA.png" rel="nofollow noreferrer">second view with data</a></p>
  
  <p>This is the code of the controller method that is called from the commandButton of the view, which is responsible for saving the data entered of the product and the respective image.</p>
  
  <pre><code>public void guardarDatosCategoria() {
  this.archivoCarga = archivoCarga;
  try (InputStream input = archivoCarga.getInputStream()) {
      String fileName = archivoCarga.getSubmittedFileName();
      Calendar hoy = Calendar.getInstance();
      DateFormat formatter = new SimpleDateFormat("yyyyMMdd-hhmmss");
      String[] ext = fileName.split("\\.");
      fileName = ext[0] + formatter.format(hoy.getTime()) + "." + ext[1];
  
      File directorio = new File(folder+"/"+this.nombreCatalogo);
  
      if(!directorio.exists()){
          if(directorio.mkdir()){
              directorio.mkdir();
              Files.copy(input, new File(directorio, fileName).toPath());                   
              //System.out.println(directorio.getAbsolutePath());                    
          }else{
              System.out.println("Error al crear directorio");
          }
      }
      //String salida = FacesContext.getCurrentInstance().getExternalContext().getApplicationContextPath();
      //System.out.println(salida);            
      Catalogo objCatalogo = new Catalogo();
      objCatalogo.setNombre(this.nombreCatalogo);
      catalogoFacadeLocal.create(objCatalogo);
  
      Imagen objImagen = new Imagen();
      objImagen.setRuta("../Resources/img/Categorias/"+this.nombreCatalogo+"/"+fileName);
      objImagen.setEstado("Principal");
      objImagen.setIdCatalogo(objCatalogo);
      imagenFacadeLocal.create(objImagen);
  
  } catch (Exception e) {
      e.printStackTrace();
  }
  this.archivoCarga=null;
  this.nombreCatalogo="";        
  </code></pre>
  
  <p>}</p>
  
  <p>This is the view code that I need to reload using f: ajax de jsf</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!--VER CATEGORIAS  --&gt;                                        
  &lt;div class="tab-pane fade active show" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab"&gt;   
    &lt;h:form id="formVerCatalogos"&gt;                                                        
        &lt;table id="table_verCatalogos" class="table"&gt;
            &lt;thead&gt;
                &lt;tr&gt;
                    &lt;th scope="col"&gt;#&lt;/th&gt;
                    &lt;th scope="col"&gt;CATEGORIA&lt;/th&gt;
                    &lt;th scope="col"&gt;TIPO&lt;/th&gt;
                    &lt;th scope="col"&gt;IMAGEN&lt;/th&gt;
                &lt;/tr&gt;
            &lt;/thead&gt;
            &lt;tbody&gt;
                &lt;c:forEach items="#{FileUploadFormBeanRequest.listarImagenes()}" var="catalogoImg" varStatus="paso" rendered="#{!empty FileUploadFormBeanRequest.listarImagenes()}" &gt;
                &lt;tr&gt;
                    &lt;th scope="row"&gt;#{paso.index+1}&lt;/th&gt;
                    &lt;td&gt;#{catalogoImg.idCatalogo.nombre}&lt;/td&gt;
                    &lt;td&gt;#{catalogoImg.estado}&lt;/td&gt;
                    &lt;td&gt;&lt;h:graphicImage id="noImagen" value="#{catalogoImg.ruta}" class="rounded img-thumbnail img_ver_categorias"&gt;&lt;/h:graphicImage&gt;  &lt;/td&gt;
                &lt;/tr&gt;
                &lt;/c:forEach&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;                                                        
    &lt;/h:form&gt;    
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>[enter image description here][3]</p>
  
  <p>This is the code of the controller that is responsible for returning the data entered, to be displayed in the table that I need to reload.</p>
  
  <pre><code>public List&lt;Imagen&gt; listarImagenes(){
  try {
      return imagenFacadeLocal.findAll();
  } catch (Exception e) {
      return null;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is how you look when the data entered is saved and the jsf ajax is executed, but the image cannot be visualized even if I look at the src of the img tag, the path is found. The only way to view the page is to reload the entire page arbitrarily, but it is not the idea.</p>
  
  <p><a href="https://i.stack.imgur.com/SofyV.png" rel="nofollow noreferrer">in this view the text rendering is done, but the image is not displayed</a></p>
  
  <p>Inspecting the element with f12, we can see that the img tag, if it has the correct path, but is not displayed with the JSF f: ajax.
  I am very grateful that you give me a help, I have already searched, read, documented and the truth is that I cannot solve it on my own, I do not understand what it takes. Happy day thank you very much.</p>
  
  <p><a href="https://i.stack.imgur.com/aWvCA.png" rel="nofollow noreferrer">INSPECTING THE VIEW WITH F12, it is shown that the src attribute has the image path</a></p>