Niagara AX之axvelocity的使用

axvelocity是一个Web模板引擎模块,来源于Apache Velocity。由于我的Niagara AX的许可没有axvelocity,因此,在palette中没有找到axvelocity。

但可以在平台的My Modules下找到它。

将axvelocity模块的module.palette下的VelocityServlet拖动到Station的Services下即可开始使用。

双击Services下的VelocityServlet,出现它的Velocity Document Manager视图。

在这个视图中可以点击下方的New按钮添加Velocity文档。

其中最重要的是选择Template File,这个文件可以是任意格式,如文本文件、HTML等,或者以vm结尾,都行,示例如下(velocity1.txt)。

模板文件选择好了,就可以通过浏览器访问它了,如下。

问题来了:

模板引擎的作用是在模板文件中显示不同Java对象的信息,这些Java对象从哪里来呢?

比如,上面展示的模板文件$user.name、$point.out.value中的user、point来自哪儿?

见下图:

velocity document的文档需要配置user、point等java对象,其属性视图如下:

从上图可以看出,需要在Velocity Document的Velocity Context属性下添加Velocity Context Ord Element。

使用结果:

可以通过axvelocity模块展示Niagara系统的信息到HTML界面上,但通过axvelocity来控制Niagara系统里面的点却有些问题,还没搞明白。

axvelocity的语法可以参考apache velocity官网的资料。

最后,Servlet Name的设置,设置完后,访问velocity document的url会有改变,如之前访问是使用:

http://localhost:82/velocity/velocity

更改servlet name后变为:

http://localhost:82/velocityz/velocity

至于在HTML页面中嵌入PX图,使用frameset+frame或者iframe都可以,关键是要设置正确的src,示例如下:

<frameset cols="300,*">
<frame src="/ord?file:^html/menu.html" />
<frame src="/ord?station:|slot:/Services" name="content" />
</frameset>

<body>
<iframe src="/ord?file:^html/menu.html" style="19%;height:100%;"></iframe>
<iframe src="/ord?station:|slot:/Services" name="content" style="80%;height:100%;"></iframe>
</body>

注意下面的url:

<body>
<a href="/ord?station:|slot:/Services/UserService" target="content">用户管理</a>
<br/>
<a href="/ord?history:/Ben0721/AuditHistory" target="content">历史记录</a>
<br/>
<a href="/velocity/velocity" target="content">velocity</a>
<br/>
<a href="/velocity/velocity2" target="content">velocity 2</a>
</body>

velocity的访问连接是不同的,没有/ord?开头

ORD可以在Workplace里通过Ctrl + L获得,去掉ORD前面的local:|fox:1912|即可。

原文地址:https://www.cnblogs.com/luo630/p/4685308.html