Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 2.04 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to fetch a column from a table(Persistence Database table) into a 'select' list of 'form' in a jsp page
  2. <s:select label="Select Category :" name="cname" list="categoryList" />
  3.        
  4. package com.rambo.action;
  5.  
  6. import beans.Category;
  7. import com.opensymphony.xwork2.ActionSupport;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import org.hibernate.Session;
  11.  
  12. public class FindCategory extends ActionSupport {
  13.  
  14.     private List<Category> cl = new ArrayList<Category>();
  15.     private List<String> categoryList = new ArrayList<String>();
  16.  
  17.     @Override
  18.     public String execute() throws Exception {
  19.         Session session = null;
  20.         try {
  21.             session = HibernateUtil.getSessionFactory().getCurrentSession();
  22.             session.beginTransaction();
  23.             this.cl = (List<Category>) session.createQuery("from Category").list();
  24.             if (this.cl.isEmpty()) {
  25.                 this.addActionError("Sorry.. No category Available. Try again Later.!");
  26.                 return ERROR;
  27.             }
  28.             for (int i = cl.size()-1; i >= 0; i--) {
  29.                 categoryList.add(cl.get(i).getName());
  30.             }
  31.             session.getTransaction().commit();
  32.         } catch (Exception e) {
  33.             this.addActionError("Oops. An Error Encountered...!");
  34.             return ERROR;
  35.         }
  36.         return SUCCESS;
  37.     }
  38. }
  39.        
  40. <property name="name" type="string">
  41.             <column name="NAME" length="20" not-null="true" />
  42.         </property>
  43.        
  44. public String getName() {
  45.         return this.name;
  46.     }
  47.  
  48.     public void setName(String name) {
  49.         this.name = name;
  50.     }
  51.        
  52. 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]
  53.  
  54. 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]