Results 1 to 2 of 2

Thread: Freemarker is impressive!

  1. #1

    Default 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.
    J2EEGuru,
    The Spring Advocate

  2. #2

    Default

    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">
    <set>
    <value>freemarkerUser</value>
    <value>velocityUser</value>
    <value>jspUser</value>
    </set>
    </property>
    </bean>

    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.
    J2EEGuru,
    The Spring Advocate

Similar Threads

  1. Replies: 3
    Last Post: Jan 8th, 2010, 02:50 AM
  2. Using taglibs in freemarker
    By swift in forum Web
    Replies: 20
    Last Post: Jan 10th, 2007, 01:06 PM
  3. Replies: 3
    Last Post: Oct 28th, 2005, 01:49 PM
  4. FreeMarker vs Velocity
    By Martin Kersten in forum Architecture
    Replies: 8
    Last Post: May 30th, 2005, 09:21 AM
  5. Freemarker Spring Macro problem
    By Gideon in forum Web
    Replies: 15
    Last Post: Jan 25th, 2005, 07:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •