Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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());


    }
}
share|improve this question
    
in action class it is avialable.So you can use from there –  PSR Jun 5 '13 at 10:23
    
No. What I mean is, in other JSP pages I can use it from action classes. But in 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
    
it is not correct to write hibernate code in jsp –  PSR Jun 5 '13 at 10:31
    
I have not written any code in JSP. The test case is in other Java class. If it is not possible, which is the best way? and Why it is not possible? –  Shiju K Babu Jun 5 '13 at 10:34
    
try to call an action from index.jsp –  PSR Jun 5 '13 at 10:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.