Page 1 of 1

Add new menu to navigation side bar

Posted: Tue Sep 15, 2015 1:59 am
by incre2012
I want to add a new menu item to the navigation side bar in the admin panel . for this I follow the instructions in this link

http://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/admin/admin-custom-controllers

But after doinmg that I get the following error message

HTTP Status 500 - org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "admin/views", template might not exist or might not be accessible by any of the configured Template Resolvers (layout/fullPageLayout:17)

Can someone tell me where I am going wrong . Please help .

Re: Add new menu to navigation side bar

Posted: Tue Sep 15, 2015 9:43 pm
by phillipuniverse
Can you post your full controller code?

Re: Add new menu to navigation side bar

Posted: Wed Sep 16, 2015 12:02 am
by incre2012
I have been able to solve the problem .

My controller code is as follows : -

Code: Select all

@Controller
@RequestMapping("/" + MyController.SECTION_KEY)
@Secured("PERMISSION_OTHER_DEFAULT")
public class MyController extends AdminAbstractController {
   protected static final String SECTION_KEY = "test";

    @RequestMapping(value = "", method = RequestMethod.GET)
    public String test(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        // This is expected by the modules/emptyContainer template, this is a custom template that gets included into the body
        model.addAttribute("customView", "test");

        // ensure navigation gets set up correctly
        setModelAttributes(model, SECTION_KEY);

        // gets the scaffolding set up to display the template from the customView attribute above
        return "modules/emptyContainer";
       
    }
}


I created the test.html at the location /admin/src/main/webapp/WEB-INF/templates/layout/partials/test.html and tried to override the admin UI by adding this to the applicationContext-servlet-admin.xml

Code: Select all

<bean id="blAdminWebTemplateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
       <property name="prefix" value="/WEB-INF/templates/layout/partials/" />
       <property name="suffix" value=".html" />
       <property name="templateMode" value="HTML5" />
       <property name="cacheable" value="${cache.page.templates}"/>
       <property name="cacheTTLMs" value="${cache.page.templates.ttl}" />
       <property name="characterEncoding" value="UTF-8" />
       <property name="order" value="200"/>         
</bean>     


Now it works fine . I was having this issue after I followed the instructions in the link

http://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/admin/admin-custom-controllers

May be I did something wrong . Thank you any way for your co-operation .

Re: Add new menu to navigation side bar

Posted: Wed Sep 16, 2015 6:18 am
by phillipuniverse
If you put the string "test" as the "customView" attribute in your controller then the admin will already look for a template at /WEB-INF/templates/test.html. It does this because this is what is inside emptyContainer.html:

Code: Select all

<div class="section-container" role="main">
    <div th:substituteby="layout/partials/stickyHeader" />

    <section class="main">
        <div th:substituteby="layout/partials/headerFlash" />
        <div th:substituteby="layout/partials/headerDetailedMsg" />
       
        <div class="row">
            <div class="twelve columns">
                <div id="sectionKey" th:text="${sectionKey}" style="display: none;" />
                <div th:substituteby="${customView}" />
            </div>
        </div>
    </section>
</div>


Note how it does this:

Code: Select all

<div th:substituteby="${customView}" />


Does it still not work if you create a test.html outside of layout/partials?

Re: Add new menu to navigation side bar

Posted: Wed Sep 16, 2015 11:34 pm
by incre2012
I tried it and now it works . I wonder what went wrong in my first attempt .