• Post Reply Bookmark Topic Watch Topic
  • New Topic

Concerns about handling RemoteException on JSP view pages.  RSS feed

 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing an application that provides a feature to search an employee database and return a list of employees. The employee object is represented by an Employee entity EJB. There will be a session bean that provides a method to obtain a list of employees based on a search criteria. I am using a controller servlet to access the session bean and get the employee search result. The servlet then sets a vector object containing the employees in the request object using request.setAttribute(). My JSP view page then accesses the vector via the request by request.getAttribute(). But I dont want the vector to contain a list of remote interfaces to Employee EJB's because the JSP view would then require code to handle RemoteException, which is an indication of a poor design. Views should be given access to simple java beans for displaying content and should not worry about handling errors. Similarly, views should not access to enterprise data directly.
So I'm wondering if it would be ok for the session bean to define a method like getEmployeesAsReadOnly(). This method would first obtain a list of Employee remote interfaces, but then it would create a list of simple Employee java beans which encapsulate the data from the Employee EJB's. Since you dont update a search result, there would be no reason to return a list of remote interfaces to a JSP view.
What do you guys think?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not only would I not return remote objects to the JSP (as you propose) but I would skip the step of creating entity beans altogether. Simply use JDBC to generate a ResultSet, load the data from the ResultSet into a Vector and send the Vector back to the JSP.
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, at least we agree about not allowing JSP's to access enterprise-level data, as in EJB's, but I think writing your own JDBC code to get a ResultSet and returning a Vector representing the ResultSet back to the JSP would be redundant. Requesting a Collection of entity EJB's doesn't neccessarily mean that they will be created each time, in fact, since the container represents a view into your database -- a virtual cache in a sense -- then you avoid database hits if the container can determine the data being requested already exists as an EJB, in which case it will return a remote interface to the EJB and not access the database.
It also would not make sence to write your own JDBC code to search for Employee data since using CMP beans places the responsibility of "finder" logic on the container.
What do you think?
SAF
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!