title: i have to set data into a html file using velocity template?
body: <p>I have a requirement in which i have to set data in a html file using velocity template. I have to create a table dynamically and also i have to show some static data. I am able to set data dynamically into table but than i am not able to get static data from my list. My problem is that i have to extract both dynamic and static data from single list only.</p>
  
  <p>Velocity code :</p>
  
  <pre><code>public static String prepareTemplate(HashMap&lt;String, String&gt; documentContentHashmap,String templateLocation) throws NamingException{
      System.out.println("Document Contents :"+documentContentHashmap);
      ArrayList documentList=new ArrayList();
      documentList.add(documentContentHashmap);
      System.out.println(documentList);
      String templatePath=templateLocation.replaceAll("\\\\","/");
      String[] splittedTemplatePath = templatePath.split("/");
      String templateName=splittedTemplatePath[splittedTemplatePath.length-1];
      VelocityEngine ve = new VelocityEngine();
      Properties properties = new Properties();
      properties.setProperty("resource.loader","file");
      properties.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
      properties.setProperty("file.resource.loader.path", templatePath.substring(0, templatePath.lastIndexOf("/"))+"/");           
      properties.setProperty("file.resource.loader.cache", "false");
      properties.setProperty("file.resource.loader.modificationCheckInterval", "0");
      ve.init(properties);
      Template t = ve.getTemplate(templateName);
      VelocityContext context = new VelocityContext();
      //for (Entry&lt;String, String&gt; entry : documentContentHashmap.entrySet()) {
          //context.put(entry.getKey(), entry.getValue());
      //}
      context.put("documentList", documentList);
      StringWriter writer = new StringWriter();
      t.merge( context, writer );
      System.out.println("writer"+writer);
      String documentBytes=generateDocument(writer);
      if(documentBytes!=null){
          return documentBytes;
      }else{
          return null;
      }
  }
  </code></pre>
  
  <p>Html file :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="ISO-8859-1"/&gt;
  &lt;title&gt;Payment Voucher&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="container"&gt;
      &lt;div id="leftDiv"&gt;
          &lt;img alt="logo" src="$image_path"/&gt;
      &lt;/div&gt;
      &lt;br/&gt;
      &lt;div id="rightDiv" style="align:right;"&gt;
          &lt;label&gt;Invoice Number :&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span&gt;Here i have to access some value from the same documentList  &lt;/span&gt;&lt;br/&gt;
          &lt;label&gt;Invoice Date :&lt;/label&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span&gt;Here i have to access some value from the same documentList &lt;/span&gt;
      &lt;/div&gt;
      &lt;table&gt;
      #foreach( $documentContent in $documentList )
          &lt;tr&gt;&lt;td&gt;$documentContent.invoice_no&lt;/td&gt;&lt;/tr&gt;
      #end
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>