RE: Newbie question regarding $!model and getParams()
"Schnitzer, Jeff" <[email protected]>
| Newsgroups | gmane.comp.web.maverick.general |
|---|---|
| Message-ID | <[email protected]> |
From: Rogers, Bob [mailto:[email protected]] > >Hi - After several days of playing around with Maverick and Velocity I've made some >progress but still have a few unanswered newbie type questions I'm hoping someone >could take the time to answer. Hi! >Question 1 - In general, where and how are the getParams() and setParam() used? >If I code 'this.getCtx().setParam("age", "55")' in the 'perform()' method, do I have >access to this in the 'transform', and more specifically, how do I reference it in >VLT? > >Is it referenced by $model.getParams() or $model.getParams("age") or >$response.getParams() .... etc. I've tried several permutations but just can't >figure it out. You would reference it by $age. For document views and transforms, params are simply set into the request attributes. The VelocityViewServlet searches this collection to evaluate expressions. You could probably access it as $request.getAttribute("age"), but that's annoying :-) Note that the current CVS version of Maverick (soon to be released as v2.2) splits up the params collection into three separate collections - controller params, view params, and transform params. This is the result of a recent thread on this list regarding redirect views. >Question 2 - I've seen in the opt-velocity friendbook example several references to >"$!model.xxx". What is the bang (ie '!') for? and why is it used? This is standard Velocity syntax for "quiet" evaluation. Normally, if there is an error evaluating $foo.bar.blah (say, the foo object doesn't have a getBar() method, or the value of getBlah() is null) then Velocity puts the "schmoo" (Velocity lingo for an unresolved expression) as-is into the body of the document. The ! means that nothing should be printed when the evaluation fails. Friendbook-velocity uses this to report errors. If there is no error, we don't want "$model.error" showing up in the html. Instead of this syntax: #if($model.error != null) $model.error #end It is much more convenient to just do: $!model.error Jeff Schnitzer [email protected] ------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger for complex code. Debugging C/C++ programs can leave you feeling lost and disoriented. TotalView can help you find your way. Available on major UNIX and Linux platforms. Try it free. www.etnus.com [INVALID FOOTER]