
Untitled
By: a guest on
Aug 12th, 2012 | syntax:
None | size: 2.04 KB | hits: 8 | expires: Never
How to fetch a column from a table(Persistence Database table) into a 'select' list of 'form' in a jsp page
<s:select label="Select Category :" name="cname" list="categoryList" />
package com.rambo.action;
import beans.Category;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
public class FindCategory extends ActionSupport {
private List<Category> cl = new ArrayList<Category>();
private List<String> categoryList = new ArrayList<String>();
@Override
public String execute() throws Exception {
Session session = null;
try {
session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
this.cl = (List<Category>) session.createQuery("from Category").list();
if (this.cl.isEmpty()) {
this.addActionError("Sorry.. No category Available. Try again Later.!");
return ERROR;
}
for (int i = cl.size()-1; i >= 0; i--) {
categoryList.add(cl.get(i).getName());
}
session.getTransaction().commit();
} catch (Exception e) {
this.addActionError("Oops. An Error Encountered...!");
return ERROR;
}
return SUCCESS;
}
}
<property name="name" type="string">
<column name="NAME" length="20" not-null="true" />
</property>
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
org.apache.jasper.JasperException: tag 'select', field 'list', name 'cname': The requested list key 'categoryList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
root cause tag 'select', field 'list', name 'cname': The requested list key 'categoryList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]