Cannot resolve view in module servlet in ACS.

cancel
Showing results for 
Search instead for 
Did you mean: 
mangar
Established Member II

Cannot resolve view in module servlet in ACS.

Jump to solution

I have a module that is supposed to display a custom freemarker template.  For testing purposes,  the method is just this simple:

    public String start() {
        return "asdf";
    }

And I am getting this error:

javax.servlet.ServletException: Could not resolve view with name 'asdf' in servlet with name 'alfresco-mvc.mvc'

My webscripts are in:  alfresco->extension->templates->webscripts->alfresco-mvc  and so is my asdf.ftl

Where should I put my templates?

Or even better,  how do I get a handle to the view resolver and set the path myself?

1 Solution

Accepted Solutions
daniel_gradecak
Active Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

it is the first time you paste that error.

Alfresco already includes a freemarker jar and it is a different version than you expect. So that is why you have to pay more attention to how you define and use things. This is not the latest spring boot version Smiley Wink

 

Make some effort and I am sure you will find the best combination that works for you.

View solution in original post

10 Replies
angelborroy
Alfresco Employee

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

You can create Freemarker web pages (Surf Pages):

https://docs.alfresco.com/content-services/latest/develop/share-ext-points/surf-pages/

Or JavaScript pages (Aikau Pages):

https://docs.alfresco.com/content-services/latest/develop/share-ext-points/aikau-pages/

Spring MVC is not supported out-of-the-box by Share application.

Hyland Developer Evangelist
mangar
Established Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

I understand it's not out of the box.  And I am not using Share at all.  It is still a Spring application, so in theory there must be a way to generate Freemarker (or any view resolver) and plug it in.

Has anyone been able to do this?  

angelborroy
Alfresco Employee

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

Not sure if @daniel_gradecak may help with that.

He was making some experiments with that in the past:

https://github.com/dgradecak/alfresco-mvc

Hyland Developer Evangelist
daniel_gradecak
Active Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

Hi,

I see that you are using alfresco-mvc. This is just a spring-mvc wrapper and is fully integrated with ACS.

The aim is to use mainly json and you either need a @RestController or a @Controller and annotated methods with @ResponseBody

But if you want to use spring views than you need to really define a Spring view but that has nothing to do with Alfresco freemarker templates and java/js controllers. 

If you want to use an Alfresco webscript and its own freemarker view refer to the Alfresco docs

but if you want to understand alfresco-mvc and spring viewes than it is purely standard Spring https://www.baeldung.com/freemarker-in-spring-mvc-tutorial

mangar
Established Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

@daniel_gradecak  

Yes,  I am using your alfresco-mvc module.  (Which I must congradulate you,  I use it in every alfresco project I work on.  It's incredible and I thank you for making it)  

My controller is annotated with @controller  and my method looks like this:

    @GetMapping("/testView")
    @ResponseBody
    public String getFreemarkerView() {
    	return "test.ftl";
    }

When I call this,  I get the actual string "test.ftl"  But when I comment out the @ResponseBody,  I get, 

 Could not resolve view with name 'test.ftl' in servlet with name 'alfresco-mvc.mvc'

And I have a test.ftl in src/main/resources

Does it look somewhere else?  Is there a way to set the template path?

daniel_gradecak
Active Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

I am glad the project helps you, it is unfortunate that alfresco does not make it stadnardSmiley Wink

 

Regarding your views, I highly recommend that you make yourself familiar with spring mvc views. Each view resolver has a configuration and can be configured in many different ways.

@ResponseBody is an anotation to specify the response content type as json usually and when you remove it Spring would look for a view resolver to return a view. I would never use freemarker today, but really just configure a resolver view in the servlet context and your a set.

 

I sent you the link and now I am pointing you to what you need https://www.baeldung.com/freemarker-in-spring-mvc-tutorial#2-configure-viewresolver but please make your self familiar with spring mvc if you want to use it. My project just enables spring mvc in ACS and I would expect you to know how to use spring mvc.

Good luck!

 

mangar
Established Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

I think I do know my MVC pretty well,  but the entire problem roots from not being able to create a freemarker config object like I normally do.  I havve used this succsessfully in plenty of Spring MVC applications:

 

	@Bean 
	public FreeMarkerViewResolver freemarkerViewResolver() { 
	    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver(); 
	    resolver.setCache(true); 
	    resolver.setPrefix(""); 
	    resolver.setSuffix(".ftl"); 
	    return resolver; 
	}
	
	@Bean 
	public FreeMarkerConfigurer freemarkerConfig() { 
	    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); 
	    freeMarkerConfigurer.setTemplateLoaderPath("/WEB-INF/views/ftl/");
	    return freeMarkerConfigurer; 
	}	

But now in alfresco,  I get:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'freemarkerConfig' defined in org.gnma.alfresco.web.config.DamsServletContext: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: 'void freemarker.template.Configuration.<init>(freemarker.template.Version)'

Which is why I was moving to some other template manager. 

daniel_gradecak
Active Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

it is the first time you paste that error.

Alfresco already includes a freemarker jar and it is a different version than you expect. So that is why you have to pay more attention to how you define and use things. This is not the latest spring boot version Smiley Wink

 

Make some effort and I am sure you will find the best combination that works for you.

daniel_gradecak
Active Member II

Re: Cannot resolve view in module servlet in ACS.

Jump to solution

FYI: Configuration(Version) was added in FreeMarker 2.3.21

and alfresco uses in their latest version freemarker-2.3.20-alfresco-patched-20200421.jar