Property value is not printing on velocity template

I am using Spring with Velocity and I try to print some literal on my velocity template, but it is not working. Here is my template, exporteComplete.vm:

${savePath}

Here is the code:

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ....
    boolean success = processor.exportCourse(courseId, exportPlayer, exportAssets, exportJson);

    ...
    if (success) {
        log.debug("Export Success");
        return new ModelAndView("templateScene/exportComplete");
    } else {
        log.debug("Export Failure");
        return new ModelAndView("templateScene/exportError", "context", context);
    }

}

Here is the method:

public boolean exportCourse(String courseId, boolean exportPlayer, boolean exportAssets, boolean exportJson) {


    context = new HashMap<Object, Object>();
    context.put("savePath", "save path complete");
    VelocityEngineUtils.mergeTemplateIntoString(engine, "templateScene/exportComplete.vm", "UTF-8", context);

    boolean test = true;

    if (test) {     
        return true;        
    }
}

I end up with ${savePath} result, when view returns exportComplete.vm.

Why it is not printing value when view returns?

EDIT ------------------------------------------------------------

This is working code.

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ....
    context = new HashMap<Object, Object>();
    boolean success = processor.exportCourse(courseId, exportPlayer, exportAssets, exportJson, context);
    if (success) {
        log.debug("Export Success");
        return new ModelAndView("templateScene/exportComplete", "context", context);

    } else {
        log.debug("Export Failure");
        return new ModelAndView("templateScene/exportError", "context", context);
    }

}

And here is the method

public boolean exportCourse(String courseId, boolean exportPlayer, boolean exportAssets, boolean exportJson, Map<Object, Object> myContext) {

    ...
    if (myContext != null) {

        myContext.put("savePath", "Save Path Complete");
        return true;

    }

}

and here is the template

${context.savePath}

Answers


savePath is a property of the context Map variable.

As the proper way to access it would be context.get("savePath"), instead of:

${savePath}

You should use:

${context.savePath}

Need Your Help

Xcode 6: Images Not Showing Up On Device

ios xcode uiimageview

I am creating UIImageView(s) and adding these views to a UIScrollView. The images show up when I am testing on a simulator, but when I test on an iphone 5s the images don't show up. Below is a list...

mutual exclusion in joomla

joomla mutual-exclusion

I created an extension for joomla using:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.