我的课程主要由String
和一些Double
组成,我有一个BeanEditor
。
但是,我希望在此类中添加另一个字段,该字段的类型是我的自定义类,我们称之为Bar
。
public class Foo {
private String myString;
private Double myDouble;
private Bar bar;
// getters and setters
...
}
该字段的允许值从数据库中提取,并应显示为选择控件。
但是,当我尝试在我的页面中执行此操作时,就像myBar
类中不存在Foo
一样。
<beaneditor>
<p:bar>
<div class="t-beaneditor-row">
<label>Bar</label>
<t:select t:id="barSelecter" t:model="barModel" t:value="foo.bar" t:encoder="barEncoder"/>
</div>
</p:bar>
</beaneditor>
如何达到预期效果?
答案 0 :(得分:2)
您必须将bar属性添加到模型中。
例如<beaneditor add="bar"... >
答案 1 :(得分:0)
您可以为类型class A{
static void greet(String name){
println "hello $name!"
}
}
//code without class declaration will be executed as part of script.run() method
A.greet("world")
编写自己的'BeanEditor'块。
就像我为TourOperator所做的那样: NamedDTOSelectTourOperatorBlocks.tml:
Bar
NamedDTOSelectTourOperatorBlocks.java:
<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd" xmlns:p="tapestry:parameter">
<t:block id="editSelectBar">
<t:label for="tourOperatorEdit" />
<t:select
value="prop:NamedDTOSelectTourOperatorEditContext.id"
t:model="tourOperatorIdsModel" t:validate="required"
t:id="tourOperatorEdit" t:blankOption="ALWAYS"
t:blankLabel="message:select.blank.label"
validate="required" />
</t:block>
</t:container>
不要忘记在public class NamedDTOSelectTourOperatorBlocks {
@Property
@Environmental
private PropertyOutputContext outputContext;
@Property
@Environmental
private PropertyEditContext editContext;
@Inject
private ComponentResources resources;
@Inject
private TourOperatorManager tourOperatorManager;
@Inject
private SelectIdModelFactoryNamedDTO selectIdModelFactoryNamedDTO;
private SelectModel tourOperatorIdsModel;
void onPrepareForRender() {
tourOperatorIdsModel = selectIdModelFactoryNamedDTO.create(tourOperatorManager.getAllNamedDTO());// Read the values from my DB
}
public SelectModel getTourOperatorIdsModel() {
if (null == tourOperatorIdsModel) {
// REMARK: I have no idea why but loading it in setupRender or onPrepareForRender seams to be too late.
tourOperatorIdsModel = selectIdModelFactoryNamedDTO.create(tourOperatorManager.getAllNamedDTO());
}
return tourOperatorIdsModel;
}
public NamedDTOSelectTourOperator getNamedDTOSelectTourOperatorEditContext() {
return (NamedDTOSelectTourOperator) editContext.getPropertyValue();
}
public NamedDTOSelectTourOperator getNamedDTOSelectTourOperatorOutputContext() {
return (NamedDTOSelectTourOperator) outputContext.getPropertyValue();
}
}
注册新定义的块:
AdminModule.java