This is probably not an appropriate occasion to use a Jersey filter, nor is
it a prudent way to use global Freemarker variables; consider moving the
population of these fields to your View concrete class. Alternately you
could extend Dropwizard's Freemarker view engine to assign some variables
in the current namespace like so:
Environment env = _cfg.getTemplate(template, locale).
createProcessingEnvironment(model, writer);
env.setLocale(locale);
env.setVariable("user", user);
env.process();
On Friday, August 25, 2017 at 3:08:43 AM UTC-4, Andrew Arrow wrote:
>
> I'm reading
> https://jersey.github.io/documentation/latest/filters-and-interceptors.html
> and http://www.dropwizard.io/1.1.4/docs/manual/core.html#jersey-filters to
> try and make this:
>
> @CookieParam("User-Data") userData: String,@HeaderParam("User-Agent")
> userAgent: String,
>
> Not needed in each and every resource GET method of my web app. userData is
> json data from a cookie with fields like "name" and "id" and userAgent is
> the full User-Agent string from the header. For each view I pass in:
>
> AppUser.getName(userData), AppUser.isMobile(userAgent)
>
> The getName function parses the json and returns just the name field and
> the isMobile function returns a true boolean if the string "mobile" is
> found.
>
> I use this in each view of the app in FreeMarker to display the user's
> name and to change some layout stuff if mobile is true.
>
> Is there a way to make this less repetitive? I'd rather use a BeforeFilter
> to just set this automatically each time.
>
--
You received this message because you are subscribed to the Google Groups
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.