我想在Velocity宏的列表中添加一个元素.这是避免出现在Velocity输出中的"真实"文本的唯一方法吗?
#set($path = [])
#set($swallow = "a")
#set ($swallow = $path.add("blaablaa"))
Run Code Online (Sandbox Code Playgroud) 我可以使用编译模板发送我的应用程序吗
我在速度的所有编译模板中都有这样的东西吗?或者他们每次运行都必须重新编译?
我有这个:
CGPoint vel = hudLayer.rightJoystick.velocity;
CCBullet* sp = [CCBullet spriteWithFile:@"green.png"];
sp.position = player.position;
[self addChild:sp z:-10];
vel = ccpMult(ccpNormalize(vel), 300);
sp.rotation = //how to get the rotation out of the velocity?
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
我有一个使用Spring MVC和Velocity的应用程序.在我的一个表单上,我想在页面顶部显示与表单相关的所有错误.我已经弄清楚如何显示与某个特定字段相关的错误(使用#springShowErrors宏),但我真的希望在表单顶部有一大块错误,而不是列出每个单独项目旁边的错误.
我做了很多谷歌搜索,有些人提出了类似的建议
#if ($status && $status.errors.hasErrors())
#foreach( $error in $status.errorMessages )
<p>$error</p>
#end
#end
Run Code Online (Sandbox Code Playgroud)
...但是当放置在将命令对象附加到表单的初始#springBind宏之下时,这不会给我输出.在每个字段的#springFormInput宏之后放置#springShowErrors工作正常,所以我知道我的验证器正在运行并产生错误.
有任何想法吗?我错过了什么真的很傻吗?
这是完整的表单,我的非工作尝试就在第一个#springBind之后
<form name="standardForm" id="standardForm" method="post" action="#springUrl("/requestAccess")">
#springBind("accessRequest")
#if ($status && $status.errors.hasErrors())
#foreach( $error in $status.errorMessages )
<p>$error</p>
#end
#end
<fieldset>
<label for="name">Name</label>
#springFormInput("accessRequest.name" " ")
<label for="company">Company</label>
#springFormInput("accessRequest.company" " ")
<label for="title">Title</label>
#springFormInput("accessRequest.title" " ")
<label for="email">Email</label>
#springFormInput("accessRequest.email" " ")
<button type="submit" value="send">Send</button>
</fieldset>
</form>
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助或建议!
我正在使用带有 CQ5 的速度模板。我安装的速度脚本引擎可以识别预定义的 CQ 对象。我想知道如何将用户定义的java对象传递给速度脚本引擎。我尝试了类似的东西: http ://groovy.codehaus.org/JSR+223+Scripting+with+Groovy
但它不起作用..请帮我解决这个情况
提前致谢
以下是我想要做的示例。我有一堆文件,例如 test1.vm:
Welcome ${name}. This is test1.
Run Code Online (Sandbox Code Playgroud)
然后我有一个名为defaults.vm的文件:
#set($name = "nmore")
Run Code Online (Sandbox Code Playgroud)
我希望使用 defaults.vm 中的变量渲染 test1.vm (和其他测试文件),而不使用 #parse,因为我必须修改所有测试文件。
有没有办法从附带的 java 文件中执行此操作?
我试图显示如下内容:
欢迎John Doe
在我的Liferay基于速度的模板中,用于WebContent
Liferay 6.2 GA1 CE
到目前为止,我的代码如下:
#set ($userLS = $portal.getClass().forName('com.liferay.portal.service.UserLocalServiceUtil'))
#set ($userId = $getterUtil.getLong($request.get("theme-display").get("user-id")))
#set ($user = $userLS.getUserById($userId))
<div class="user-welcome">
#if($user.isMale())
<span class="welcome-msg">Bienvenido</span><br>
#else
<span class="welcome-msg">Bienvenida</span><br>
#end
<span class="username">$user.getFullName() $user.getLastName()</span>
</div>
Run Code Online (Sandbox Code Playgroud)
我遇到的错误是:
$user.isMale()
总是返回falsespan.username
的输出中是代码本身.它不打印该值.提前致谢
ResourceLoader
API文档中有一个类:
我想实现自己的加载器,因为我需要从数据库加载模板,但是以上下文敏感的方式(换句话说:无法使用 DataSourceResourceLoader,我需要编写自定义代码以从数据库)。
似乎ResourceLoader
有一些抽象方法,而且我似乎也可以通过实现这些抽象方法来编写自定义加载器。但我没有看到任何方法可以向引擎添加新的加载程序。没有“addResourceLoader”方法。该文档仅显示如何配置 Velocity 中内置的加载器:
https://velocity.apache.org/engine/2.0/developer-guide.html#resource-loaders
主要问题:如何将自定义资源加载器添加到 VelocityEngine(或 VelocityContext?)
另一个附带问题:我想关闭所有内置加载器。特别WebappResourceLoader
是它默认处于活动状态,并且在我的特定应用程序中代表了安全风险。怎么做?
所以我在遗留项目中使用 Velocity。甚至渲染中等大小的页面也需要 FOREVER。字面意思是 10+ 分钟。
我一定遇到了某种错误……其他人对 Velocity 的总体体验很糟糕吗?我即将开始单步执行源代码,看看它挂在哪里/等,但我想看看 SO 不得不说些什么。:)
velocity ×9
java ×5
aem ×1
apache ×1
forms ×1
iphone ×1
liferay ×1
liferay-6 ×1
math ×1
performance ×1
return-value ×1
rotation ×1
scriptengine ×1
sling ×1
spring ×1
spring-mvc ×1
validation ×1