jqueryajaxspringapache-tiles

Does apache tiles refreshe all attributes each time?


Before using Apache tiles in my spring application, I want to confirm if apache tiles reloads all of layout attributes (such as Header, Menu, Body, footer) a new page is being loaded.

Can you confirm its working for every new page load? Also, which is better option to be used ajax div load vs apache tiles?


Solution

  • The servlet container will notice changes in your JSP files and recompile them (if it's not configured otherwise, of course); for example when you change

    <title><tiles:insertAttribute name="foo" /></title>
    

    to

    <title><tiles:insertAttribute name="bar" /></title>
    

    The tile definitions (i.e. the tiles.xml file) are only loaded on startup by default. According to the documentation, you can add a filter that's supposed to reload the tiles definitions if needed.

    <filter>
        <filter-name>Tiles Filter</filter-name>
        <filter-class>org.apache.tiles.web.startup.TilesFilter</filter-class>
        <init-param>
            <param-name>
              org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
            </param-name>
            <param-value>
              /WEB-INF/tiles-defs.xml,/org/apache/tiles/classpath-defs.xml
            </param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>Tiles Filter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>
    

    Unfortunately, it didn't seem to work in my case.

    Another source suggests using this instead:

    <context-param>
      <param-name>org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO.CHECK_REFRESH</param-name>
      <param-value>true</param-value>
    </context-param>
    

    ...but this didn't work for me either.


    Re: "ajax div load vs apache tiles" : I'm not entirely sure what you mean by the first one, assuming this would be fetching HTML fragments at runtime via AJAX, I believe Tiles would perform better as the page would be generated on server-side, in AJAX solution user's browser would have to assemble it bit by bit. It all depends on your use case, really (how dynamic is the page? does it ever change during user's session?)