I'm trying to populate a drop down list in a grid column using the Struts2-jQuery-grid-3.7.0 plugin as follows.
<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"/>
And the action where the CategoryList action is mapped is as follows.
@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;
}
}
When a given edit link on the grid is clicked, the load() method is executed where a list of categories is loaded from the database.
The list in the grid however, displays nothing in edit mode (when the edit link is clicked). I cannot find relative examples that may demonstrate this kind of thing.
How to populate this drop down list especially, how to give this drop down labels using the catName property and values using the catId (of Long type) property separately (while category in the list has many other attributes)?
I don't find relevant examples to map a java.util.List<E> to <sjg:grid>.
subCategory.category.catName is a nested property of Product entity.
In this case, even after populating the list, it should also be noted that the display value of this column is catName (category name of type String). The value of the selected item however, to be set to an instance of Product should be catId (category id of type Long) which doesn't seem possible as the name of this column is subCategory.category.catName.
Intuitively, catId (subCategory.category.catId) would be mapped to catName (subCategory.category.catName) which would be wrong, if I could envision correctly as if the list were already populated.