Link to home
Create AccountLog in
Avatar of greddin
greddinFlag for United States of America

asked on

How to reuse a serverbean?

I have the following code (which is working as expected). I would like to know how to reuse the server bean on line #5?

As you can see now, it's calling service called "GET_DOCTYPES" and building a Select list from these. Below this list, I would like to call a different service "GET_DOCTYPES_BY_ID" using the same serverbean.

Do I need to place another jsp:useBead line with something like id="sb2"?

What's the best way to do this?

<%@ page errorPage="testjsperrorpage.jsp" session="true" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="idcserver.*" %>
<jsp:useBean id="sb" scope="page" class="idcserver.ServerBean" />
<%
	sb.init(request);
	sb.parseExecuteService("IdcService=GET_DOCTYPES");
	ServerResultSet results = sb.getResultSet("DocTypes");
%>
 
<html>
<head>
<title>test5.jsp</title>
</head>
 
<h3>DocTypes:</h3>
 
<form name="form1">
<select size="1" name="dDocTypes" onchange="document.form1.submit();">
<option value="none">Please Select...</option>
 
<%
String docType = request.getParameter("dDocTypes");
 
	for (results.first(); results.isRowPresent(); results.next())
	{
		String dDocType = results.getStringValue("dDocType");
		String dDescription = results.getStringValue("dDescription");
		if (docType!=null && docType.equals(dDocType)) {
			out.println("<option value='" + dDocType + "' selected>" + dDescription + "</option>");
		}
		else {
			out.println("<option value='" + dDocType + "'>" + dDescription + "</option>");
		}
	}
%>
 
</select>
</form>
 
<%
if (docType != null) {
	out.println("<br>dDocType length is " + docType.length());
	out.println("<br><br>Form was submitted with the value: " + docType);
}
%>
 
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mohammedf
mohammedf
Flag of Palestine, State of image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of greddin

ASKER

It seems I can reuse again just be calling it again. Please see code.
<jsp:useBean id="sb" scope="page" class="idcserver.ServerBean" />
 
<%
sb.init(request);
sb.parseExecuteService("IdcService=GET_DOCTYPES");
ServerResultSet results = sb.getResultSet("DocTypes");
%>
 
...later on on same page
 
<%
sb.parseExecuteService("IdcService=GET_DOCTYPES_BY_NAME");
ServerResultSet results2 = sb.getResultSet("DocTypes");
%

Open in new window