How to display the active object table data in velocity template?

Alok Singh May 2, 2015

I have an active object table created where I am able to add data. Now I am trying to retrieve all the data with this piece of code.

@Override
public List<ProdConf> getAllProducts()
{
 
    List<ProdConf> prodConfs = newArrayList(ao.find(ProdConf.class, Query.select()));
    for (ProdConf prodConf : prodConfs) {
        System.out.println("Name:" + prodConf.getProdName());
    }
    return prodConfs;
}
 
 
//Action Command
public String doManageProd() throws  Exception{

	prodConfs = prodConfService.getAllProducts();


for (ProdConf prodConf : prodConfs)
{
    System.out.println(prodConf.getProductName())
}
 
return "manageprod";
}

Now when I am using $action.prodConf.getProductName() , it is not showing any value. Please help.

 

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2015

I guess that in you action you can have a method that returns prodConfService and then iterate objects in the velocity:

// action code:
public ProdConfService getProdConfService() {
  return prodConfService;
}
 
in the velocity template:
#set ($allProducts = $action.prodConfService.getAllProducts())
#foreach ($product in $allProducts)
  $product.getProdName()
#end

Other approach is to have in your action a method that returns collection of objects and similarly access this method from a template.

Alok Singh May 3, 2015

Thanks a lot Volodymyr, it worked :)

TAGS
AUG Leaders

Atlassian Community Events