I have a custom taglib with namespace xyz. I want to access the methods of this taglib in a service. If I import it and use xyz.someFunction(). It does not recognize it. How do we access the namespace of a taglib from outside?
Asked
Active
Viewed 2,575 times
3
-
1This link shows you, I believe. http://stackoverflow.com/questions/2159423/how-to-call-a-taglib-as-a-function-in-a-domain-class – John Gordon May 12 '12 at 12:02
2 Answers
5
if you want to use your custom taglib in service class, use the code below.
def c = grailsApplication.mainContext.getBean('com.custom.MyCustomTagLib');
int age = c.calculateAge(dob);
More details can be found here

Ashish Joseph
- 1,103
- 3
- 12
- 35
-1
Taglibs contain logic related to view whereas services contain business logic. I dont see any reason for using taglibs in services. If you are doing so, it's probably a design mistake. Can you please give a reason of why you want to use taglib in services?

Gagan Agrawal
- 139
- 1
- 9
-
I was using the service which send emails. And in order to follow the DRY principle I wished to use already written code. – zade May 14 '12 at 09:06
-
I would suggest to move that common logic in some service or utility class instead of having it in taglib. – Gagan Agrawal May 25 '12 at 16:05