File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Registering Function Mapper for Custom tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Registering Function Mapper for Custom tags" Watch "Registering Function Mapper for Custom tags" New topic
Author

Registering Function Mapper for Custom tags

Matt Coole
Greenhorn

Joined: Oct 25, 2011
Posts: 2
Hi there,

I'm trying to use some jstl string functions in an expression in my custom tag e.g.

<my:customtag value="#{fn:substringBefore('teststring', 'string')}"/>

This expression works fine when used in other tags e.g. hutputText however when used in my own custom tag results in;

javax.faces.el.ReferenceSyntaxException: javax.el.ELException: Expression uses functions, but no FunctionMapper was provided

I've searched on this topic but can find no helpful articles other than how to implement your own FunctionMapper, but even these do not tell you how to register the implementation for use.

I don't want to implement my own but simply register the one provided in my server (Tomcat 6) for use in my custom tag.

Does anyone know how to do this? I presume it's something simple you declare in your tag library but I can find no examples anywhere.

Thanks in advance to anyone who can help
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Welcome to the Ranch, Matt!

I'm afraid I can't be of immediate help. It would require that I go back and RTFM . I try to avoid creating custom JSF tags at the binary level these days for a number of reasons. One of which, fortunately, is that the set of powerful third-party extension tagsets available right now is so good. Custom tags are expensive to create and maintain, so I let some other poor sucker do it for me when I can. Failing that, the next alternative is to create Facelets components, and only then do I break out the binary option.

The main reason I stuck my nose in, however, was to proffer some (possibly unwanted) advice. While it's nice that we can do things like add custom EL extensions, putting logic on JSF view definitions is a violation of the MVC contract, which says that the view should reflect what's in the model. One reason is that one doesn't have to figure out which file the logic is in because it's always in a standard place. Another is that it's a heck of a lot easier to run a debugger against POJO logic in the backing bean than it is to trace through the EL processor. So use those awesome powers wisely!


Customer surveys are for companies who didn't pay proper attention to begin with.
Matt Coole
Greenhorn

Joined: Oct 25, 2011
Posts: 2
Thanks for the advice Tim and your speedy response. I agree with what you're saying about keeping any such logic out of the jsf pages but in my case I am choosing the lesser of two evils. My cutom tag is rendering an embedded object and custom set of controls for the object to a jsf page however the embedded object is a bit nasty, suffice to say it has lead me to need to construct a complete url for on of it's parameters. Obviously I could do this on the server side when rendering my component but due to where the source of the url (coming out of a servlet) this would lead to my tag being tied into my jsf application and not being very re-usable. I suppose I could bash this logic out to a backing bean somewhere and have my component retrieve the url from there to keep with the mvc concepts but it's only a simple function I'm wanting to perform and only in this one specific context.

I will continue my search
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

FWIW, here's how I managed to specify absolute URLs with a minimum of complexity:


The pageContext bean grabbed the FacesConfig to get the HttpServletRequest to get the context from its URL. So that particular bean does have javax.faces specialized code in it, but it localizes the dependency on JSF to that particular bean so I don't have it splattered all over the webapp.>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Registering Function Mapper for Custom tags
 
Similar Threads
evaluate ${variable} where variable contains ${}
EL versus Tag Libraries
Custom Display Regulator Tag and Interface
Generating <script> tag from Custom JSF Tag
Keeping all these tags straight...