December 5, 2016

Jasperreports - print Array or ArrayList horizontally

If you want to add any wraper to the report, just use "List" Component, but it is tricky to fill it from your Bean and print horizontally. Here is a working solution. I want to display on the "Product variant" page also "Product variant Sizes" in a horizontal List, first row are Sizes Names and the second row are available Sizes Count :
public class ProductVariant {
...
    private List selectedSizes;
...

}

public class SelectedProductVariantSize  {
...
    private int count;
    private ProductVariantSize size;
...
}

public class ProductVariantSize  {
...
 private String name;
        public String getName() {
  return name;
 }
...
}



in JRXML file, just add list, in "Appereance tab"set "Layouts" as "Vertical layout", in "List" tab set "Ignore Width" as true, and "Print Order" as Horizontal.
 



 
 
 
 
 
 
 
 
 
 
 
  
   <![CDATA[_THIS]]>
  
  
 
 
 
     
   
    
     
     
    
    
     
      <![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{selectedSizes})]]>
     
     
      
       
       
        
        
        
        
       
       
        
       
       <![CDATA[$F{size}.getSize().getName()]]>
      
      
       
       
        
        
        
        
       
       
        
       
       <![CDATA[$F{size}.getCount()]]>
      
     
    
   
  
 

The result:



 This solution is based on this answer and this answer.