0

I have gone through other post of rendering the view using spring3.2.5 & tiles3

in my context-servlet.xml

<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
  <property name="viewClass">
     <value>
        org.springframework.web.servlet.view.tiles3.TilesView
     </value>
  </property>

In my tiles-servlet.xml

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
     <list>
          <value>/WEB-INF/tiles/common/tiles.xml</value>
          <value>/WEB-INF/tiles/common/base_tiles.xml</value>
              <value>/WEB-INF/tiles/common/person_tiles.xml</value>
      </list>
</property>
</bean> 

In person_tiles.xml

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
   "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>

     <definition name="new_person" extends="base.definition">
        <put-attribute name="body" value="/WEB-INF/xx/xxx/web_person.jsp" />
     </definition>
</tiles-defnitions>

It throws below error javax.servlet.ServletException: Could not resolve view with name 'new_person' in servlet with name 'project'

please help me to solve the issue.

SpareMe
  • 71
  • 7

2 Answers2

1

After lot of digging I found that tiles is not loading the resources properly.

Here i am not sure whether it is a bug (spring 3.2.5 & tiles 3.0.1) or not:

But I solved this issue by following

here in my tiles-servlet.xml

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
      <list>
        <value>/WEB-INF/tiles/common/tiles.xml</value>
        <value>/WEB-INF/tiles/common/baseTiles.xml</value><!-- Change the base_tiles to baseTiles.xml or base.xml -->
        <value>/WEB-INF/tiles/common/personTiles.xml</value><!-- Change the person_tiles.xml to personTiles.xml or person.xml-->
      </list>
   </property>
</bean>

Here when we have the definitions value as separated with underscore (ex: person_tiles or base_tiles) it is not loading the resource.However tiles.xml the tiles-definitions are accessible.

But I tried with tiles 2.2 & spring 3.2.5 it works correctly. Even though we give as person_tiles or base_tiles.xml.

In tiles-servlet.xml

Change the base_tiles & person_tiles to baseTiles & personTiles, and changed the file names accordingly.

OR

Change the base_tiles & person_tiles to base & person, and changed the file names accordingly.

I hope somebody can find it as useful.

SpareMe
  • 71
  • 7
1

Related issue discussing this "behavior" is SPR-11491 and is specific to Tiles v3.

It comes from SpringWildcardServletTilesApplicationContext.getResources(String) -> URLApplicationResource(String, URL) constructor -> super PostfixedApplicationResource(String localePath) constructor. When there is an underscore in definition filenames, the string after the last underscore is identified as the locale.

The Tiles section of Spring 4.0.3 reference documentation has been updated in order to make this behavior more explicit, and there are ongoing discussion with Tiles development team to get this fixed by checking the locale against Locale.getISOLanguageCodes() in order to get a less surprising default behavior.

Sébastien Deleuze
  • 5,950
  • 5
  • 37
  • 38
  • After 4 hours of debugging I can confirm this was our issue. I had app_tiles.xml and once I changed it to just tiles.xml it worked file. – Dot Batch Apr 01 '16 at 14:57