css - spring mvc with entire html template -


i have spring-boot app using uses spring-mvc html. no thymeleaf, no jsp. able apply themes app, way cms's such joomla , wordpress do. problem every spring-mvc template article/posting talks either using single css file, or using tiles. if have 15 themes, each in own folder (they typically seem have many css, js, , html files), not sure how can apply theme app dynamically (selecting via drop down example).

has done this? conceptually don't see problem, short of manually moving each template related file under /template, don't know how best accomplish this.

using velocity viewresolver possible it.

i'm using configuration:

<bean id="velocityconfig" class="org.springframework.web.servlet.view.velocity.velocityconfigurer">         <property name="resourceloaderpath" value="/web-inf/views/"/>         <property name="velocityproperties">             <props>                 <prop key="input.encoding">utf-8</prop>                 <prop key="output.encoding">utf-8</prop>             </props>         </property>     </bean>     <!-- #velocity -->     <bean id="viewresolver" class="org.springframework.web.servlet.view.velocity.velocitylayoutviewresolver">         <property name="cache" value="true" />         <property name="prefix" value="" />         <property name="suffix" value=".vm" />         <property name="layouturl" value="layout1.vm" />         <property name="contenttype" value="text/html;charset=utf-8" />     </bean> 

the property layouturl there default template, html file inside webapp/web-inf/views/ folder:

layout1.vm:

<html> <body> <h1>hello world 1!</h1>  $screen_content  </body> </html> 

the velocity view resolver replace $screen_content view contents of controller response:

mycontroller.java

...  @requestmapping("/mycontroller") public string mycontroller() {     return "myview1"; } ... 

so, if view myview1.vm inside webapp/web-inf/views/ like:

<h2> foo bar! </h2> 

the result of request /myapp/mycontroller like:

<html>     <body>     <h1>hello world 1!</h1>      <h2> foo bar! </h2>      </body>     </html> 

and if want use template, can set dynamically on controller, setting value on model var:

...  @requestmapping("/mycontrollerwithadifferentlayout") public string mycontroller2(model m) {     m.addattribute("layout", "layout2");     return "myview1"; } ... 

when setting "layout" attribute on model, velocity use provided view template.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -