Using detached hibernate pojos as JavaBeans within a JSP


Web tier: servlets, JSP, Web frameworks: Using detached hibernate pojos as JavaBeans within a JSP

  1. I'm trying to migrade a series of JSPs from using scriptlets and script variables to use JavaBeans to get access to the various tag libraries and define my own. One of the technicial hurtles I have enountered is understanding how to make detached hibernate pojos and collections of them available as javaBeans within the JSP. The tutorials I have seen have dealt with javaBeans as user inputs, but what I need is returned from the server. A sample of the type of JSP follows .... .... ***some conditional html using the current device**** How could the above be rewritten with JavaBeans so I could use the various conditional tags Any help would be apprieciated. -fazle
  2. Step 1 : Define a JavaBean with a getter, setter method for your devices public class DeviceBean { private List devices; public List getDevices(){ return devices; } public List setDevices(List devices){ this.devices =devices; } } Step 2 : In your controller class (depending on the MVC framework you are using) you need to set the following deviceBean.setDevices(deviceManager.getDevices()); // Device manager would your service class to pick up the domain object from DAO Step 3: Set the device bean to the scope u want, say request request.setAttribute("deviceBean",deviceBean); Step 4 : In your jsp u could use ${} U could be using scriplets,Struts html tags , custom tags or JSTL ijn ur jsp In your jsp , the devices bean will be looked up the scope heirarchy and displayed when it finds one Hope it answers ur question
  3. thanks[ Go to top ]

    Thanks for the info