2

Is it possible to call a function of Java class through dynamically generated function from StringTemplate ?

for instance, following is a Java class with three functions

public class RegionManager {

    public static List<String> getCenter(){
       return somelist; 
    }   

    public static List<String> getFloor(){
         return somelist;   
    }

    public static List<String> getRoom(){
         return somelist;   
    }   

}

Now, my String template file contains $CS.name$ .. the value of could be "Room", "Floor", "Center".

based on the $CS.name$ value, I want to call function ( could be getRoom(), getFloor(), getCenter() ) . Please note that When I write String template file, I do not know , which function is going to be called.

2

2 Answers 2

3

You can't call static functions. You can only call getters on objects.

Sign up to request clarification or add additional context in comments.

Comments

2

As it was already mentioned, you can't call static functions in your template. However, there is another interesting mechanism, which can help you out with your requirement.

StringTemplate library has a mechanism of custom Renderers.

You can build a renderer, which will call your static method, based on the input and / or potentially format e.g.

<your_item; format="your_format">

I hope that will help to solve your problem. It helped me a lot in different templates.

1 Comment

Both links are broken/require signup.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.