aspose file tools*
The moose likes JForum and the fly likes Freemarker support for JSP taglibs in JForum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » JForum
Bookmark "Freemarker support for JSP taglibs in JForum" Watch "Freemarker support for JSP taglibs in JForum" New topic
Author

Freemarker support for JSP taglibs in JForum

Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
In order to integrate JForum with my site, I'd like to be able to use some custom tags and other JSP features in the header and footer templates.

According to the freemarker docs, it directly supports using JSP tags like so:
<#assign bean=JspTaglibs["/WEB-INF/mytaglib.tld"]>

It turns out that this causes an "Expression JspTaglibs is undefined" error. What seems to be the problem is that JForum doesn't use the "TaglibFactory" model which is needed for Freemarker to support taglibs.

Now I don't really know anything about freemarker except what I've learned today, but I'm not sure why this can't be added. Tt looks like JForum just directly uses the Freemarker library with a "SimpleHash" as the model instead of using the Freemarker servlet. But in keeping with this system, can we also add support for the TaglibFactory model?

I'm comfortable making the changes myself, but I could use some suggestions to point me in the right direction.

Thanks!
[originally posted on jforum.net by csbook]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Hi there.

Did you manage to workaround this issue. I am just getting started with jforum and I need to include a common header from another jsp file that is using struts taglibs. I have tried adding com.opensymphony.webwork.views.JspSupportServlet to web.xml but I still get following error ;

assignment: html=JspTaglibs["/WEB-INF/struts-html.tld"] [on line 5, column 1 in default/header.htm] in include "header.htm" [on line 1, column 1 in default/forum_list.htm] ---------- Java backtrace for programmers: ---------- freemarker.core.InvalidReferenceException: Expression JspTaglibs is undefined on line 5, column 15 in default/header.htm. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)

Is there any alternate way to integrate jsp struts html tags into freemarker template?

Thanks.
[originally posted on jforum.net by shah_m]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Hey, I know this post is a bit late, but maybe it can be helpful to people who are still having this problem.

I had this same error when I was trying to put custom tags into some of the JForum pages and I managed to get it working (I am using JForum 2.1.8 ). The problem is due to the fact that there are some missing context attributes required by Freemarker for it to support custom tags.

Here is a link to the Freemarker manual where they explain how to integrate custom tags in your templates:
http://freemarker.sourceforge.net/docs/pgui_misc_servlet.html
Scroll down to the section titled "Using JSP custom tags in FTL"

To save you time, here is the code I added to the net.jforum.JForum class in the "service" method. I added the code just before the call to "processCommand"


Hope this helps,
Jason
[originally posted on jforum.net by marlingj]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
Hi Can you show the header.htm code where you inserted the JSP Tags.

Thanks,
Jude
[originally posted on jforum.net by judekm]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
This is the code I used to include the tag lib on the page. The url you see here is the taglib uri and is the same one I defined in the TLD file for my tag library. You'll have to check your particular TLD file to know what your URL should be.


And this is the code I used to call one of the tags from my tag library. This tag doesn't have any attributes as you can see.

[originally posted on jforum.net by marlingj]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
The Taglib class is




The XML is



Its working but just wanted to make sure whether it is good enough for production.
[originally posted on jforum.net by judekm]
Migrated From Jforum.net
Ranch Hand

Joined: Apr 22, 2012
Posts: 17424
If it works then it works. But there might be an easier way than implementing your own custom tag to do an include.

For instance you might try the Freemarker include directive which you could just put on the page you want to do the include from



Or you might also try to use the JSP include directive. I'm not sure how freemarker supports the built-in JSP tag lib though, so this one might not work.
[originally posted on jforum.net by marlingj]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Freemarker support for JSP taglibs in JForum
 
Similar Threads
JSP Compatibility
[Ask] Template or What? to be a "View" technology for Struts2
problem iterating over header in JSP with JSTL
Exception occurs when using s2 tags in *.ftl
[Architecture] Frameworks, tools, plugins and etc - What next