Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The suffix property SpringTemplateLoader doesn't work #21

Open
bee06 opened this issue Dec 28, 2016 · 4 comments
Open

The suffix property SpringTemplateLoader doesn't work #21

bee06 opened this issue Dec 28, 2016 · 4 comments

Comments

@bee06
Copy link

bee06 commented Dec 28, 2016

hi;
The suffix property of SpringTemplateLoader doesn't work,Configuration follows:

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

Controller follows:

@RequestMapping(value = "/jade.json", method = RequestMethod.GET)
    public ModelAndView test(ModelAndView model) {
        model.setViewName("pages/index.pug");
        return model;
    }

The View Name must be added “.pug”

I hope so:

@RequestMapping(value = "/jade.json", method = RequestMethod.GET)
    public ModelAndView test(ModelAndView model) {
        model.setViewName("pages/index");
        return model;
    }

I'm using the following jar files:

<dependency>
                <groupId>de.neuland-bfi</groupId>
                <artifactId>spring-jade4j</artifactId>
                <version>1.2.5</version>
            </dependency>

            <!-- https://mvnrepository.com/artifact/de.neuland-bfi/jade4j -->
            <dependency>
                <groupId>de.neuland-bfi</groupId>
                <artifactId>jade4j</artifactId>
                <version>1.2.5</version>
            </dependency>

Can anyone please help me?

@bee06
Copy link
Author

bee06 commented Dec 28, 2016

Don't know that I use is right?

@bee06
Copy link
Author

bee06 commented Dec 28, 2016

SpringTemplateLoader‘s code:

private Resource getResource(String name) {

		String resourceName = basePath + name;
        if (hasNoExtension(resourceName)) {
			resourceName += suffix;
		}
		return this.resourceLoader.getResource(resourceName);
	}

If basePath is not null,replace the name‘s suffix

@jackcholt
Copy link

I also have the same problem. Since Jade is now known as Pug I thought I should change the suffix to ".pug". So I changed the name of my template file to home.pug and changed my configuration as follows (I'm using GroovyConfig instead of XML or JavaConfig):

@bean
SpringTemplateLoader templateLoader() {
new SpringTemplateLoader(basePath: '/WEB-INF/views/', encoding: 'UTF-8', suffix: '.pug')
}

The Controller class that is supposed to load the page has this method:

@RequestMapping('/home')
String home(Model model) {
if (!view) {
throw new IllegalStateException('The view was never initialized')
}
view
}

When I attempt to load 'home' in my browser (using "http://localhost:8080/home) I get the following stackdump in my log:

ERROR [de.neuland.jade4j.spring.view.JadeView] - <failed to render template [home]

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/views/home.jade]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at de.neuland.jade4j.spring.template.SpringTemplateLoader.getReader(SpringTemplateLoader.java:54)
at de.neuland.jade4j.lexer.Lexer.(Lexer.java:48)
at de.neuland.jade4j.parser.Parser.(Parser.java:47)
at de.neuland.jade4j.JadeConfiguration.createTemplate(JadeConfiguration.java:86)
at de.neuland.jade4j.JadeConfiguration.getTemplate(JadeConfiguration.java:65)
at de.neuland.jade4j.spring.view.JadeView.getTemplate(JadeView.java:67)
at de.neuland.jade4j.spring.view.JadeView.doRender(JadeView.java:59)
at de.neuland.jade4j.spring.view.JadeView.renderMergedTemplateModel(JadeView.java:30)
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)

It appears to be ignoring the value of the 'suffix' field of de.neuland.jade4j.spring.template.SpringTemplateLoader.

All of this worked great before I tried to change the suffix.

I have forked the source code and am trying to troubleshoot.

@jackcholt
Copy link

There is also a thread about this in the Jade4J issues but I'm thinking it might be better to fix this in a new project called pug4j based on jade4j which hasn't been created yet (see thread about need for pug4j project).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants