【发布时间】:2014-03-26 02:14:57
【问题描述】:
我正在尝试使用Struts2-jQuery-grid-3.7.0 插件在网格列中填充下拉列表,如下所示。
<s:url id="dataURL" action="CategoryList" namespace="/admin_side"/>
<sjg:gridColumn name="subCategory.category.catName"
index="subCategory.category.catName"
edittype="select"
searchtype="select"
formoptions="{label:'Select'}"
surl="%{dataURL}"
editoptions="{dataUrl : '%{dataURL}'}"
editrules="{required: true}"
title="Category" width="200"
sortable="true" search="true"
editable="true" sorttype="text"/>
而CategoryList动作映射到的动作如下。
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value="struts-default")
public final class CategoryList extends ActionSupport implements Serializable {
@Autowired
private final transient Service service = null;
private List<Category>categories = new ArrayList<Category>();
private static final long serialVersionUID = 1L;
public List<Category> getCategories() {
return categories;
}
@Action(value = "CategoryList",
results = {
@Result(name = ActionSupport.SUCCESS, location = "Product.jsp"),
@Result(name = ActionSupport.INPUT, location = "Product.jsp")},
interceptorRefs = {
@InterceptorRef(value = "defaultStack", params = {"validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
public String load() throws Exception {
System.out.println("load called...");
categories = service.getCatgeoryList();
return ActionSupport.SUCCESS;
}
}
当单击网格上的给定编辑链接时,将执行 load() 方法,从数据库中加载类别列表。
但是,网格中的列表在编辑模式下(单击编辑链接时)不显示任何内容。我找不到可以证明这种事情的相关例子。
尤其是如何填充此下拉列表,如何使用catName 属性和值分别使用catId(Long 类型)属性赋予此下拉标签(而列表中的category许多其他属性)?
我找不到将java.util.List<E> 映射到<sjg:grid> 的相关示例。
subCategory.category.catName 是Product 实体的嵌套属性。
在这种情况下,即使在填充列表后,也要注意该列的显示值为catName(String类型的类别名称)。然而,要设置为 Product 实例的所选项目的值应该是 catId(Long 类型的类别 ID),这似乎是不可能的,因为该列的名称是 subCategory.category.catName。
直观地说,catId (subCategory.category.catId) 将被映射到 catName (subCategory.category.catName),如果我能正确地设想,就好像列表已经填充一样。
【问题讨论】:
-
添加了 struts2-jquery 标签,因为它有 31 个关注者,而您的其他 sj 标签有 3 个关注者...
-
如果有人有,请添加答案。
标签: jsp struts2 struts2-jquery struts2-jquery-grid struts2-jquery-plugin