How to use custom function in the report

Stimulsoft Reports.JAVA discussion
Post Reply
zzzz
Posts: 19
Joined: Thu Apr 09, 2015 3:30 am

How to use custom function in the report

Post by zzzz »

hello
If i want to use the method in the java class(in the jar files).What should i do for registering the function in the designer.
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How to use custom function in the report

Post by Vadim »

Hello.
You can in StiRenderReportAction (like in Samples\webfx\ MyRenderReportAction) define custom function:

Code: Select all

public StiReport render(StiReport report) throws IOException, StiException {
         // Add custom function
        report.getCustomFunctions().add(new StiCustomFunction() {
            public Object invoke(List<Object> args) {
                return ((String) args.get(0)).substring((Integer) args.get(1),
                        (Integer) args.get(2));
            }

            @SuppressWarnings({ "rawtypes", "unchecked" })
            public List<Class> getParametersList() {
                return new ArrayList<Class>(Arrays.asList(String.class, Integer.class,
                        Integer.class));
            }

            public String getFunctionName() {
                return "subStr";
            }
        });
        return super.render(report);
    }
zzzz
Posts: 19
Joined: Thu Apr 09, 2015 3:30 am

Re: How to use custom function in the report

Post by zzzz »

hello.
I've done it in your way.
Here is my MyRenderReportAction define a custom function named subString.I made a breakpoint here,but haven't implemented.
What did I miss?
Image
ApplicationInitializer
Image
web.xml
Image
mrt File
Image
Exception
Image
Attachments
Exception.png
Exception.png (46.04 KiB) Viewed 5811 times
mrtFile.png
mrtFile.png (23.22 KiB) Viewed 5811 times
web.xml.png
web.xml.png (4.23 KiB) Viewed 5811 times
ApplicationInitializer.png
ApplicationInitializer.png (26.98 KiB) Viewed 5811 times
MyRenderReportAction.png
MyRenderReportAction.png (32.88 KiB) Viewed 5811 times
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How to use custom function in the report

Post by Vadim »

Hello.
Plase use next code (Integer->Long)

Code: Select all

public StiReport render(StiReport report) throws IOException, StiException {
           report.getCustomFunctions().add(new StiCustomFunction() {
            public Object invoke(List<Object> args) {
                return ((String) args.get(0)).substring(((Long) args.get(1)).intValue(), ((Long) args.get(2)).intValue());
            }

            @SuppressWarnings({ "rawtypes", "unchecked" })
            public List<Class> getParametersList() {
                return new ArrayList<Class>(Arrays.asList(String.class, Long.class, Long.class));
            }

            public String getFunctionName() {
                return "subStr";
            }
        });
        return super.render(report);
    }
Сan you make sure that the function render() invoke ?
zzzz
Posts: 19
Joined: Thu Apr 09, 2015 3:30 am

Re: How to use custom function in the report

Post by zzzz »

hello.
I use this code in jsp,custom function can work.Thanks for your help :D .But what ApplicationInitializer.java and listener in web.xml do?

Code: Select all

MyRenderReportAction myRenderReportAction = new MyRenderReportAction();
report = myRenderReportAction.render(report);
zzzz
Posts: 19
Joined: Thu Apr 09, 2015 3:30 am

Re: How to use custom function in the report

Post by zzzz »

hello.
what ApplicationInitializer.java and listener in web.xml do?
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How to use custom function in the report

Post by Vadim »

Hello.
It need to initialize applications settings.
zzzz
Posts: 19
Joined: Thu Apr 09, 2015 3:30 am

Re: How to use custom function in the report

Post by zzzz »

Vadim_Matveev wrote:Hello.
It need to initialize applications settings.
Not used to register a custom method?
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How to use custom function in the report

Post by Vadim »

Hello.
zzzz wrote:Not used to register a custom method?
Yes
Post Reply