If you ask my opinion about template system - current template system used by jforum is ugly and complex without a reason. (I do not want to say that "standard" JSP is much better).
The reason why jforum template system is bad are:
1. it uses reflect, thus throwing away strong
java strong typing.
2. it uses homegrown ugly template language. You already have a good modern language - java, use it.
3. It does not allow compile-time check.
My proposition is to use modified JSP system, from which I cleaned all garbage, put there by SUN.
Think of a template as a java code with HTML addition (not as of HTML with java addition as SUN wants you to think).
And think of JSP only as a preprocessor which converts .jsp to .java files.
An example of a page template look as following
------- example.jsp -------------
public static void printFormA(java.io.PrintWriter out,ActionServletRequest request,
String name,String value) {
headers.printHeader(out);
%>
<FORM ACTION="/test">
<INPUT NAME="<~ name %>" VALUE="<%~ value %?">
</FORM>
<%~ I18n.getMessage("some message")} %>
<% printSomethingElse(out,value); %>
<%
<br /> headers.printFooter(out);
}
static printSomethingElse(java.io.PrintWriter out,String value)
{
%> print some other HTML <%
<br /> }
---------- end of example.jsp -----------------
Simple JSP-like preprocessor would convert this to example.java
and when you need to call this template you just do in java main code
net.jforum.templates.example.printFormA(out,request,name,value);
This way you:
1. Have every template identified by java signtanutes of method(s).
2. You call these method directly as java code!!! No reflect any more (slow, works poorly, vary hard to debug, you may find out you have an error only after months of
testing). Think "this is ugly" every time you use reflect.
3. You pass all data to template as java methods arguments.
4. If you need some code in template - then open <%
<br /> and you have all power of java, without any homegrown hack-language.
If you want - I cane send you .jsp perprocessor (trivial thing).
The main idea is to use all power of java and have typecheck at compile time and that every templates is identified by java method(s).
If you subscribe yo this idea - I would send you code and examples.
[originally posted on jforum.net by Anonymous]