I am using Spring, Hibernate and Struts2 for my Java web application. I have created DAOs, Services for Some tables in the database and I am able to process with that in my Action class. Now I want to populate a <select>
option in my JSP page to display one table contents.
But the problem is, Select box is in index.jsp, That is it should display the options when the application is loading(before calling any action classes).
I don't know how to use hibernate in JSP to get data. If it was in other JSP pages, I could have done that by using Action class before the other JSP page loads.
Entity Bean
@Entity
@Table(name = "AAI_SubjectArea")
public class AAISubjectArea {
private String aAIColumnName;
private String aAISubjectAreaName;
private String aAISubjectAreaDes;
private String aAITableName;
//Getters and setters
Service Interface
public interface IAAISubjectAreaService {
public List<AAISubjectArea> getAllAAISubjectArea();
}
DAO Interface
public interface IAAISubjectAreaDao {
public List<AAISubjectArea> getAllAAISubjectArea();
}
Service Implementation
public class AAISubjectAreaServiceImpl implements IAAISubjectAreaService{
@Autowired
private IAAISubjectAreaDao aAISubjectAreaDao;
public void setAAISubjectAreaDao(IAAISubjectAreaDao aAISubjectAreaDao) {
this.aAISubjectAreaDao= aAISubjectAreaDao;
}
@Override
public List<AAISubjectArea> getAllAAISubjectArea(){
return ref_LookUpDao.getAllAAISubjectArea();
}
}
DAO Implementation
public class AAISubjectAreaDaoImpl implements IAAISubjectAreaDao{
@Autowired
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public Session getSession() {
Session session = sessionFactory.openSession();
return session;
}
private int BATCH_SIZE = 50;
@Override
public List<AAISubjectArea> getAllAAISubjectArea(){
String queryString = "from AAISubjectArea as aAISubjectArea";
Session session = getSession();
Query query = session.createQuery(queryString);
List<AAISubjectArea> aAISubjectAreaList = query.list();
return aAISubjectAreaList;
}
}
Here is a Test Case which is working fine.
public class SubjectAreaTestCase extends BaseDAOTest{
@Autowired
IAAISubjectAreaDao aAISubjectAreaService;
@Test
public void testGetIAISubjectArea() {
List listAppType = aAISubjectAreaService.getAllAAISubjectArea();
System.out.println(listAppType.size());
}
}
index.jsp
I want to use hibernate. And it is not calling the action class anyway before page loads. I want to display options when the application loads the first page(before calling any action classes) – Shiju K Babu Jun 5 '13 at 10:31