java - Velocity + Spring -
i attempting setup webapp above components. i've jumped last hurdle integrating spring & velocity tools. saw this post morning, , updated different answer provided. however, once attempted add in parametertool 1 of templates so:
#foreach( $key in $params.keyset() ) $key = $params.getvalue($key) <br /> #end
i receive npe java.lang.unsupportedoperationexception: request null. parametertool must initialized first! according i've read means tooling configured properly, doesn't have access request. note: receive error accepted solution well.
has been able use these tools spring? seems it's known deficiency there open jira open jira spr-5514
a modified version of the accepted answer this question resolves issue.
instead of returning viewcontext need return viewtoolcontext. need prepare toolboxes , set them on session / request applicable:
you need initialize toolcontext in whichever manner need (look @ provided answer here on how updated apis, you're going need access toolboxfactory.
the modified createvelocitycontext method need prepare toolboxes prior creating viewtoolcontext in following manner:
protected context createvelocitycontext(map <string, object> model, httpservletrequest request, httpservletrespsone response) throws exception { initvelocitycontext(); //still keep toolcontext static //will need add //the servletcontext -- left exercise preparetoolboxes(request, response); context context = new viewtoolcontext(getvelocityengine(), request, response, getservletcontext()); //set model attrs context .... return context; } private void preparetoolboxes(final httpservletrequest request, final httpservletresponse response) { string key = toolbox.class.getname(); if (factory.hastools(scope.request && request.getattribute(key) == null) { toolbox requesttools = factory.createtoolbox(scope.request); request.setattribute(key, requesttools); } if (factory.hastools(scope.session) { httpsession session = request.getsession(); synchronized(factory) { //follow pattern above } } }
Comments
Post a Comment