在Tapestry中通用的property selection model
【IT168技术文档】
具体使用如下,假如现在有一个配件类型的类
java 代码
创建配件类时,需要选择配件类型public class FittingType ...{
private Long id;
private String name;
private Set fittings = new HashSet();
//getter and setter
![]()
}
java 代码
Html中定义组件private IPropertySelectionModel fittingTypeSelectionModel;
![]()
public IPropertySelectionModel getFittingTypeSelectionModel() ...{
![]()
if (fittingTypeSelectionModel == null) ...{
![]()
List fittingTypes = getFittingTypeService().findAll();
![]()
fittingTypeSelectionModel = new ObjectPropertySelectionModel(
![]()
fittingTypes, FittingType.class, "getName", "getId", true,
![]()
"选择分类");
}
return fittingTypeSelectionModel;
}
public abstract Long getFittingTypeId();
public ILink onSave() ...{
//其他
if (getFittingTypeId() != null) ...{
![]()
fitting.setType(getFittingTypeService()
![]()
.findByID(getFittingTypeId()));
![]()
}
![]()
//其他
}
java 代码
具体定义中"type@PropertySelection" model="ognl:fittingTypeSelectionModel"
value="ognl:fittingTypeId" displayName="配件类型"/>
参数1:候选的ListfittingTypeSelectionModel = new ObjectPropertySelectionModel(
![]()
fittingTypes, FittingType.class, "getName", "getId", true,
![]()
"选择分类");
![]()
}
参数2:类别
参数3:label的getter方法
参数4:option的getter方法
参数5:是否允许没有选项
参数6:没有选项时的label
0
相关文章
