Execute Report via Menu link

Hi,

I am trying to execute the report when the link on Menu is clicked.
To achieve this I am using the rptGuiMgr.printReport(r,reportParams);
in init Method of a Blank screen.
But my problem is when the report is loaded, a blank screen is displayed.
Calling close method within init is not working.

Please let me know if there are any Suggestions?

Hi,

According to the menu.xml docs - CUBA Platform. Developer’s Manual

You can pass a runnable implementation or reference a class from a menu item. Then you don’t need a dedicated screen.

Bye
Mario

1 Like

Hi Mario,
Thanks for a quick response.
I had tried extending then Runnable class. But the dataservice variable is not getting instantiated inside this class, hence i am not able to execute the printReport.
Also, since the Bean will not be able to access the web components I am not able to use the ReportGuiManager object inside the Bean.

Any help is appreciated.

Thanks :slight_smile:

Aruna.

Runnable class is not a Spring bean, so injection doesn’t work there.

If you need to get an instance of DataService (or other service or other Spring bean) in any class outside of Screen controller’s code or Spring beans’s code - you need to use AppBeans.get() method:

DataManager dataManager = AppBeans.get(DataManager.NAME);

Thanks Alex will try this and let u know

Thanks a lot Alex and Mario. :smiley:
These suggestion helped in solving the problem.

Pasting my Code for reference
in web-menu.xml:

<menu description="Output Report" >
    <item class="com.company.web.Directreportlink"/>
</menu>

in the web module a class (Directreportlink.java) is created that implements Runnable:
A service method is returning the Report Object which is consumed , customService.getReport(rptName);

public class Directreportlink  implements Runnable {
  protected ReportGuiManager rptGuiMgr = AppBeans.get(ReportGuiManager.class);
  protected CustomService customService = AppBeans.get(CustomService.class);

@Override
public void run() {
    String rpt_name = "Report_Name";
    fetchAndDisplayReport(rpt_name);
}
public void fetchAndDisplayReport(String rptName)
{
    Map<String, Object> reportParams = new HashMap<>();
    Report r = customService.getReport(rptName);
    if(r!=null){
        rptGuiMgr.printReport(r, reportParams);
    }
    else
    {
        System.out.println("Printing:Some Error Occured");
    }
  }
}