Announcement Announcement Module
No announcement yet.
Freemarker is impressive! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Freemarker is impressive!

    I switched my views from jsp to ftl in a sample spring app last week. I have been very happy with freemarker. I only have one problem. In the JSP version, I have a custom tag renders a menu item for users belonging to specific roles. I could create a macro to do the same thing but I am not sure how to do that in freemarker since the request object is exposed in ftl. Is there a way to call isUserInRole(...) in freemarker? Perhaps, such functionality should be added to spring's RequestContext object which is exposed to ftl. If I can do that, I may permanently switch to ftl especially since my container (weblogic 8.1) does not support JSP 2.0 which, although not as powerful as freemarker, would simplify my life.

  • #2
    To facilitate view substitutability, I have implemented the following solution.

    1. In my sample-servlet.xml, I define a set of application roles which are the same roles that are defined in web.xml.

    <bean id="applicationRoles" class="org.springframework.beans.factory.config.Se tFactoryBean">
    <property name="sourceSet">

    2. After a successful authentication, I iterate over the set of roles to check for the user's membership. If the user is a member, then I add the application role to the User object's roles property. At the end of the iteration, I have all the roles to which the user belongs. Next, The User object is stored in a UserSession object inside the HttpSession object and all controllers can retrieve that User object and make it or some of its properties available to the view.

    3. Now a JSP or a freemarker page can determine if menu item with a specified set of roles should be rendered since the user's valid roles are accessible on the page.