سؤال

I am new in Tiles, and I like it.

My problem is, that I got a head , body and footer tile in the template definition in SpringFramework. I would like to display some user information in head tile, and display last login ip in footer with some dynamic data. As I mean I can do that, if I assagn(addAttribute) every variable in every controller which use this template.

Is there any way the head/footer tile ask data from there own spring Controller? Or how can I add information(variableValue) to head and footer tiles without repeating sourcecode in every controller.

Thanks

هل كانت مفيدة؟

المحلول 2

Spring Interceptor solve this (example: http://dzone.com/tutorials/java/spring/spring-interceptor.html)

نصائح أخرى

There may be a couple ways to accomplish this, but one way might be through a Filter.

In your web.xml you would define a new filter and map it to all urls, i.e.

<filter>
  <filter-name>myFilter</filter-name>
  <filter-class>path.to.my.filter.MyFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>myFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

You would then create a class at the path specified in the <filter-class> element (path.to.my.filter.MyFilter in this case) and create the actual filter.

As for implementations of the filter, there are also a few ways of going about it, I'd recommend using a Spring implementation since it will be easier to integrate. Below is an example from a different stack overflow post I used for a Flash Map implementation. It uses a OncePerRequestFilter, so every request this filter will be called. If you wish to use this filter type, I'd recommend storing these values in the Session so they're only executed once, then just retrieved on each request, saving some processing time.

https://github.com/donkeystalk/floor41/blob/master/floor-41/src/main/java/octane/floor/filters/FlashMapFilter.java

Hope this helps.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top