JSP, JavaBenas and Struts problem :(
Hi All,
Well i have tried several approachs...but I am not able to get properties of a bean object on a jsp page.
The situation is, I am creating a new java bean instances for every row in the result set. I am storing those bean objects into an ArrayList. Then I am setting that arraylist object into my session scope in my action servlet.
The problem is, I can see the arraylist in the debugger, it has all the properties loaded init. But, I was not able to iterate and print those values on my jsp page. Here is my code for my ActionServlet, JavaNean and JSP page...
detailSearchAction.java- an ActionServlet
***************************************************************************
public class detailSearchAction extends Action {
private String TARGETPAGE = null;
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
detailSearchActionForm dsa = (detailSearchActionForm) form;
ArrayList resultObjects = new PerformSearch().primarySearchUsecaseOne();
HttpSession session = request.getSession();
if(dsa.getName() != null && dsa.getName() != ""){
TARGETPAGE = "success";
session.setAttribute("INITIAL_RESULTS",resultObjects);
//request.setAttribute("SEARCH_FORM",dsa);
}else{
TARGETPAGE = "failure";
}
return mapping.findForward(TARGETPAGE);
}
}
initialSearch.java - JavaBean
***************************************************************************
public class initialSearch extends Object implements Serializable {
public static final String HOST_ID = "hostid";
public static final String PLANT_GENUS = "plantgenus";
private String hostid;
private String plantgenus;
private PropertyChangeSupport propertySupport;
public initialSearch() {
propertySupport = new PropertyChangeSupport(this);
}
public String getHostId() {
return hostid;
}
public void setHostId(String value) {
String oldValue = hostid;
hostid = value;
propertySupport.firePropertyChange(HOST_ID, oldValue, hostid);
}
public String getPlantGenus(){
return plantgenus;
}
public void setPlantGenus(String value){
String oldValue = plantgenus;
plantgenus = value;
propertySupport.firePropertyChange(PLANT_GENUS, oldValue, plantgenus);
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
propertySupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
propertySupport.removePropertyChangeListener(listener);
}
}
detailResults.jsp- JSP page for Printing the results.
***************************************************************************
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="http://displaytag.sf.net" prefix="dispaly"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Success!</title>
</head>
<body>
<h1>The search results are as under.</h1>
The search result string is: ${INITIAL_RESULTS[1]}
<c:set var="initialsearch" value="${INITIAL_RESULTS}"/>
<c:set var="size" value="${fn:length(initialsearch)}"/>
<c:forEach begin="0" end="${size-1}" var="count">
<jsp:useBean class="resultBeans.initialSearch" id="initS">
<jsp:getProperty name="initS" property="hostid"/>
</jsp:useBean>
</c:forEach>
Modify your search <a href="indexLeafMiners.jsp">here</a>!
</body>
</html>
Message was edited by:
jini4java

