spring - Use Tiles without `views.properties` -


i'm trying reduce of configuration of our web application , have noticed our views.properties file has lot of redundant values can calculated programmatically.

for example:

welcome.(class)=org.springframework.web.servlet.view.tiles2.tilesview welcome.url=welcome  home.(class)=org.springframework.web.servlet.view.tiles2.tilesview home.url=home  login.(class)=org.springframework.web.servlet.view.tiles2.tilesview login.url=login 

is there way entirely without views.properties file (i'd rather more opinionated "file names must match view names" error-prone "updated these x config files")

thanks time!

so have been using hack rid of lame views.properties file 6 years now. here amazing solution of laugh at/use:

define viewresolver way instead

<bean id="viewresolver" class="com.yourcompany.util.tilesresourcebundleviewresolver"/> 

here implementation of resolver looks directly @ tiles views

package com.yourcompany.util;  import java.util.locale; import java.util.missingresourceexception; import javax.servlet.http.httpservletrequest; import org.apache.struts.tiles.definitionsfactory; import org.springframework.beans.beansexception; import org.springframework.context.applicationcontextexception; import org.springframework.web.servlet.view; import org.springframework.web.servlet.view.tiles.tilesview; import org.apache.struts.tiles.defaulttilesutilimpl; import org.springframework.mock.web.mockhttpservletrequest; import org.springframework.web.servlet.view.abstractcachingviewresolver;  /**  * dave's improved view resolver because hates having many files  * update every time creates new view. spring makes bad enough!  *  * @author dave  */ public class tilesresourcebundleviewresolver extends abstractcachingviewresolver {     private final string content_type = "text/html;charset=utf-8";      /**      * incomprehensible reason tiles stuff requires http request      * in order see if view exists.      */     private static final httpservletrequest fake_http_request =         new mockhttpservletrequest();      @override     protected view loadview(string viewname, locale locale) throws         missingresourceexception, beansexception, exception     {         // check if view defined         // in site-views.xml , let tiles worry         definitionsfactory definitionsfactory =             (definitionsfactory) getservletcontext().getattribute(                 defaulttilesutilimpl.definitions_factory);         if (definitionsfactory == null)         {             throw new applicationcontextexception(                 "tiles definitions factory not found: tilesconfigurer not defined?");         }         if (definitionsfactory.getdefinition(viewname,             fake_http_request, getservletcontext()) == null)         {             //log.warn("request unknown view: " + viewname);             viewname = "pagenotfound";         }          tilesview t = new tilesview();         t.setbeanname(viewname);         t.seturl(viewname);         t.setapplicationcontext(getapplicationcontext());         t.setcontenttype(content_type);         return t;     } } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -