Results 1 to 5 of 5

Thread: Tiles 2.1 with Spring 2.5.4

  1. #1
    Join Date
    Feb 2007
    Posts
    12

    Default Tiles 2.1 with Spring 2.5.4

    Hello everyone,

    Does anyone have idea about the issue of integration between Tiles 2.1 and Spring 2.5.4? I know many people have this issue before. Does Spring has official solution about that?

    Thanks

    Yi

    I got the error like:

    PHP Code:
    Mar 302009 3:31:40 PM PDT> <Error> <HTTP> <BEA-101017> <[weblogic.servlet.internal.WebAppServletContext@1b47cc2 appName'WebRoot'name'WebRoot'context-path'/WebRoot'Root cause of ServletException.
    org.springframework.beans.factory.BeanCreationExceptionError creating bean with name 'tilesConfigurer' defined in ServletContext resource [/WEB-INF/maxnext-servlet.xml]: Invocation of init method failednested exception is java.lang.UnsupportedOperationException: Class org.apache.tiles.web.util.ServletContextAdapter not recognized a TilesApplicationContext
        at org
    .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1336)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:471)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        
    at java.security.AccessController.doPrivileged(Native Method)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        
    Truncatedsee log file for complete stacktrace
    java
    .lang.UnsupportedOperationException: Class org.apache.tiles.web.util.ServletContextAdapter not recognized a TilesApplicationContext
        at org
    .apache.tiles.factory.TilesContainerFactory.createContainer(TilesContainerFactory.java:219)
        
    at org.springframework.web.servlet.view.tiles2.TilesConfigurer.createTilesContainer(TilesConfigurer.java:214)
        
    at org.springframework.web.servlet.view.tiles2.TilesConfigurer.afterPropertiesSet(TilesConfigurer.java:201)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1367)
        
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1333)
        
    Truncatedsee log file for complete stacktrace 

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    There are some solutions on the forum (use the search) but for the time being spring isn't compatible with Tiles 2.1.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2007
    Posts
    12

    Default Tiles 2.1

    Thanks Marten, I looked around forum couple times, however, I did not see a solid solution there. Could you please post a link if you have?

    thanks very much.

    Yi

  4. #4

    Default

    Quote Originally Posted by Marten Deinum View Post
    There are some solutions on the forum (use the search) but for the time being spring isn't compatible with Tiles 2.1.
    How the Spring 2.5.6?

    We are using Tiles 2 with Spring MVC and we are really stuck. The Spring 3 doesn't support Tiles at all. We have to roll back to Spring 2.5.

  5. #5
    Join Date
    Apr 2009
    Posts
    1

    Default Tiles 2.1.2

    This solution picks up all xml files from given location and seems to be working with Tiles 2.1.2.

    config:
    Code:
       <bean id="tilesConfigurer"
         class="com.xxx.web.context.TilesConfigurer">
         	<property name="definitionPath" value="/WEB-INF/tiles-defs"></property>
         	<property name="definitionPattern" value="^.*\.xml$"></property>
        </bean>
    java:
    Code:
    import java.util.ArrayList;
    import java.util.Enumeration;
    import java.util.List;
    import java.util.Properties;
    import java.util.Set;
    
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    
    import org.apache.log4j.Logger;
    import org.apache.tiles.TilesApplicationContext;
    import org.apache.tiles.TilesContainer;
    import org.apache.tiles.TilesException;
    import org.apache.tiles.access.TilesAccess;
    import org.apache.tiles.context.AbstractTilesApplicationContextFactory;
    import org.apache.tiles.context.ChainedTilesApplicationContextFactory;
    import org.apache.tiles.context.ChainedTilesRequestContextFactory;
    import org.apache.tiles.definition.DefinitionsFactory;
    import org.apache.tiles.definition.UrlDefinitionsFactory;
    import org.apache.tiles.factory.AbstractTilesContainerFactory;
    import org.apache.tiles.factory.TilesContainerFactory;
    import org.apache.tiles.preparer.BasicPreparerFactory;
    import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
    import org.apache.tiles.web.util.ServletContextAdapter;
    import org.springframework.beans.factory.DisposableBean;
    import org.springframework.beans.factory.InitializingBean;
    import org.springframework.util.StringUtils;
    import org.springframework.web.context.ServletContextAware;
    import org.springframework.web.servlet.view.tiles2.SpringLocaleResolver;
    
    import com.xxx.utils.CollectionsUtils;
    
    public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean {
    	protected Logger logger = Logger.getLogger(TilesConfigurer.class);
    	
    	private ServletContext servletContext;
    	
    	private TilesApplicationContext tilesContext;
    	
    	private String definitionPath;
    	
    	private String definitionPattern;
    	
    	private final Properties tilesPropertyMap = new Properties();
    	
    	public TilesConfigurer() {
    		this.tilesPropertyMap.put(
    				AbstractTilesContainerFactory.CONTAINER_FACTORY_INIT_PARAM,
    				TilesContainerFactory.class.getName());
    		this.tilesPropertyMap.put(
    				AbstractTilesApplicationContextFactory.APPLICATION_CONTEXT_FACTORY_INIT_PARAM,
    				ChainedTilesApplicationContextFactory.class.getName());
    		this.tilesPropertyMap.put(
    				TilesContainerFactory.REQUEST_CONTEXT_FACTORY_INIT_PARAM,
    				ChainedTilesRequestContextFactory.class.getName());
    		this.tilesPropertyMap.put(
    				TilesContainerFactory.DEFINITIONS_FACTORY_INIT_PARAM,
    				UrlDefinitionsFactory.class.getName());
    		this.tilesPropertyMap.put(
    				TilesContainerFactory.PREPARER_FACTORY_INIT_PARAM,
    				BasicPreparerFactory.class.getName());
    		this.tilesPropertyMap.put(
    				UrlDefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY,
    				SpringLocaleResolver.class.getName());
    
    	}
    
    	@Override
    	public void setServletContext(ServletContext servletContext) {
    		this.servletContext = servletContext;
    	}
    
    
    	public void setDefinitionPath(String definitionPath) {
    		this.definitionPath = definitionPath;
    	}
    
    	public void setDefinitionPattern(String definitionPattern) {
    		this.definitionPattern = definitionPattern;
    	}
    
    	/**
    	 * Set the Tiles definitions, i.e. the list of files containing the definitions.
    	 * Default is "/WEB-INF/tiles.xml".
    	 */
    	public void setDefinitions(String[] definitions) {
    		if (definitions != null) {
    			String defs = StringUtils.arrayToCommaDelimitedString(definitions);
    			if (logger.isInfoEnabled()) {
    				logger.info("TilesConfigurer: adding definitions [" + defs + "]");
    			}
    			this.tilesPropertyMap.put(DefinitionsFactory.DEFINITIONS_CONFIG, defs);
    		}
    	}
    	
    	public void init() {
    		List<String> definitions = new ArrayList<String>();
    		getResources(definitionPath, definitions);
    		
    		String[] defs = new String[definitions.size()];
    		definitions.toArray(defs);
    		
    		setDefinitions(defs);
    	}
    	
    	public void afterPropertiesSet() throws TilesException {
    		init();
    		
    		ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
    		tilesContext = new ServletTilesApplicationContext(adaptedContext);
    		
    		AbstractTilesContainerFactory factory = AbstractTilesContainerFactory.getTilesContainerFactory(tilesContext);
    		TilesContainer container = factory.createContainer(tilesContext);
    		TilesAccess.setContainer(tilesContext, container);
    	}
    
    	@SuppressWarnings("unchecked")
    	private void getResources(String path, List<String> definitions) {
    		Set<String> paths = servletContext.getResourcePaths(path);
    		
    		if (!CollectionsUtils.isEmpty(paths)) {
    			for (String lPath : paths) {
    				if (lPath.matches(definitionPattern)) {
    					definitions.add(lPath);
    				} else
    					getResources(lPath, definitions);
    			}
    		}
    	}
    
    	@Override
    	public void destroy() throws Exception {
    		TilesAccess.setContainer(this.tilesContext, null);
    	}
    
    	/**
    	 * Internal implementation of the ServletConfig interface, to be passed
    	 * to the wrapped servlet. Delegates to ServletWrappingController fields
    	 * and methods to provide init parameters and other environment info.
    	 */
    	private class DelegatingServletConfig implements ServletConfig {
    
    		public String getServletName() {
    			return "TilesConfigurer";
    		}
    
    		public ServletContext getServletContext() {
    			return servletContext;
    		}
    
    		public String getInitParameter(String paramName) {
    			return tilesPropertyMap.getProperty(paramName);
    		}
    
    		@SuppressWarnings("unchecked")
    		public Enumeration getInitParameterNames() {
    			return tilesPropertyMap.keys();
    		}
    	}
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •