0

I recently picked Spring framework for my university project on Java course, picked Jade4J for my template engine already put the dependancy in pom.xml and installed the package but when i'm calling the Jade4J.render("./index.jade", model); but I'm getting "./index.jade (File not found)" response. Uppon looking in the github repo there's no particular information how to make configuration class with the directory it will look for templates. I even tried to put the index.jade file everywhere in the project(controller dir, dir where main.java is implemented, resources dir, webapp dir). I'd appreciate any help I'll provide any further information if necessary

Edit 1
Added JadeConfig class to project with the content:

@Bean
public SpringTemplateLoader templateLoader() {
    SpringTemplateLoader templateLoader = new SpringTemplateLoader();
    templateLoader.setBasePath("/templates/");
    templateLoader.setEncoding("UTF-8");
    templateLoader.setSuffix(".jade");
    return templateLoader;
}

@Bean
public JadeConfiguration jadeConfiguration() {
    JadeConfiguration configuration = new JadeConfiguration();
    configuration.setCaching(false);
    configuration.setTemplateLoader(templateLoader());
    return configuration;
}

@Bean
public ViewResolver viewResolver() {
    JadeViewResolver viewResolver = new JadeViewResolver();
    viewResolver.setConfiguration(jadeConfiguration());
    return viewResolver;
}

My index controller has the following function:

@GetMapping(value = "/")
public String greeting() throws IOException {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("title", "Index Page");
    String html = Jade4J.render("./index.jade", model);
    return html;
}

And lastly the template index.jade path is src\main\webapp\templates\index.jade

B0re
  • 239
  • 1
  • 8

2 Answers2

2

For new people which tries to find info of Jade4j.

Here you can find the example which works without errors and other examples of template engine https://github.com/jreijn/spring-comparing-template-engines

The main question is do you really need Jade4j?

The last release was 2017 year and he doesn't have a big community https://mvnrepository.com/artifact/de.neuland-bfi/jade4j

Max
  • 21
  • 4
0

Did you check out the Spring integration for Jade4j https://github.com/neuland/spring-jade4j

It details how Jade4j can be configured with Spring Beans.

<bean id="templateLoader" class="de.neuland.jade4j.spring.template.SpringTemplateLoader">
    <property name="basePath" value="/WEB-INF/views/" />
</bean>

<bean id="jadeConfiguration" class="de.neuland.jade4j.JadeConfiguration">
    <property name="prettyPrint" value="false" />
    <property name="caching" value="false" />
    <property name="templateLoader" ref="templateLoader" />
</bean>

<bean id="viewResolver" class="de.neuland.jade4j.spring.view.JadeViewResolver">
    <property name="configuration" ref="jadeConfiguration" />
    <!-- rendering nice html formatted error pages for development -->
    <property name="renderExceptions" value="true" />
</bean>
allu
  • 381
  • 1
  • 8
  • Used the Spring JavaConfig option to implement the beans but still getting the same error, I made an edit on the description; provided some code from my project. This answer was already helpful bcs you provided how to config Spring – B0re Oct 23 '18 at 13:11
  • Did you try with just Jade4J.render("index.jade", model); – allu Oct 23 '18 at 13:16
  • Yes i tried all posibilities index index.jade ./index.jade also putting the dir templates into main, resources – B0re Oct 23 '18 at 13:51