简体   繁体   中英

Add Arguments to Rythm template using Java

I'm writing a MVC portlet framework and I plan to use Rythm inside my views. I would like to pass various arguments to the view and was wondering if there is a way to declare these arguments for the view using Java at runtime? I know that I can declare arguments in the view using the @args tag and that I can add custom tags from Java, but I wanted to do something similar to how ASP.NET MVC passes helper classes (HtmlHelper @Html, UrlHelper @Url, Object @Model) to the view.

If all the arguments you planned to pass to the view are global (ie they applied to all render session and to all templates) then you should treated them as implicit variables, meaning template author don't need to declare them but they are free to use them. Examples of implicit variables are session, request, context etc.

For how to declare implicit variables, you can refer to:

For how to configure Rythm engine with your implicit variable, refer to

For how to inject implicity variables into rythm engine for each render session, you can also refer to:


For things like HtmlHelper my recommendation is to provide reusable rythm template as tags instead of Java object. Because you need to render html snippet, thus using rythm is a natural way to go instead of let the Java code to output the content.

For things like UrlHelper if it is all about String manipulation, you can go straight with Java code, but probably the public static method is more appropriate than helper instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM