读取速度模板中映射的模型对象 [英] Reading model objects mapped in Velocity Templates
问题描述
我有一个 Struts + Velocity 结构,例如一个 Person 类,它的一个属性是一个 Car 对象(具有自己的 getter/setter 方法),并且它被映射到一个 Velocity 表单,该表单使用 ModelDriven 提交给一个 Action和 getModel 结构.
I have a Struts + Velocity structure like for example, a Person class, whose one property is a Car object (with its own getter/setter methods) and it is mapped to a Velocity form that submits to an Action, using ModelDriven and getModel structure.
如果 car 属性不为 null 或 car.id != 0,我应该在表单上放置一个按钮,显示查看汽车",或者如果汽车为 null 或 car.id = 0,则显示另一个按钮选择汽车".
I what to put a button on the form that shows "View Car" if car property is not null or car.id != 0 or show another button "Choose Car" if car is null or car.id = 0.
我该如何编码.我在模板文件中尝试了类似的东西:
How do I code this. I tried something like that in the template file:
#if($car != null)
#ssubmit("name=view" "value=View Car")
#else
#ssubmit("name=new" "value=Choose Car")
#end
但我一直在 #if 行中收到有关 Null 值的错误.
But I keep getting error about Null value in the #if line.
我还在 Person 中创建了一个布尔方法 hasCar() 来尝试,但我无法访问它,也不知道为什么.
I also created a boolean method hasCar() in Person to try, but I can't access it and I don't know why.
而且 Velocity + Struts 教程很难找到或有很好的信息.
And Velocity + Struts tutorials are difficult to find or have good information.
谢谢
推荐答案
您应该将 #if 行更改为:
You should change the #if line to:
#if($car)
这篇关于读取速度模板中映射的模型对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!