Page 1 of 1

How to use custom function in the report

Posted: Thu Aug 06, 2015 9:14 am
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.

Re: How to use custom function in the report

Posted: Thu Aug 06, 2015 10:42 am
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);
    }

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 4:13 am
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

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 6:12 am
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 ?

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 6:37 am
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);

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 7:32 am
by zzzz
hello.
what ApplicationInitializer.java and listener in web.xml do?

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 8:23 am
by Vadim
Hello.
It need to initialize applications settings.

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 8:29 am
by zzzz
Vadim_Matveev wrote:Hello.
It need to initialize applications settings.
Not used to register a custom method?

Re: How to use custom function in the report

Posted: Mon Aug 10, 2015 9:39 am
by Vadim
Hello.
zzzz wrote:Not used to register a custom method?
Yes