技术开发 频道

在Tapestry中通用的property selection model


IT168技术文档】 
    具体使用如下,假如现在有一个配件类型的类 

    java 代码
public class FittingType { private Long id; private String name; private Set fittings = new HashSet(); //getter and setter }
    创建配件类时,需要选择配件类型 

    java 代码
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())); } //其他 }
    Html中定义组件 

    java 代码
"type@PropertySelection" model="ognl:fittingTypeSelectionModel"
value
="ognl:fittingTypeId" displayName="配件类型"/>
     具体定义中 
fittingTypeSelectionModel = new ObjectPropertySelectionModel( fittingTypes, FittingType.class, "getName", "getId", true, "选择分类"); }
     参数1:候选的List 

     参数2:类别 

     参数3:label的getter方法 

     参数4:option的getter方法 

     参数5:是否允许没有选项 

     参数6:没有选项时的label




0
相关文章