This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Generating a Dropdown from a bean to a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generating a Dropdown from a bean to a JSP" Watch "Generating a Dropdown from a bean to a JSP" New topic

Generating a Dropdown from a bean to a JSP

Stewart Williams

Joined: Jul 15, 2002
Posts: 4
I am having a problem with generating a JSP form that keeps the data after validation has detected bad user data. I have attempted and failed. I created a bean that generates a dropdown with the correct data, but I can't seem to get the data to keep. I believe the reason is because it is instantiating another bean and not the one the jsp had generated. Below is the code for the bean and Jsp

<%@ taglib uri='tlds/update.tld' prefix='query' %>
<%@ page import="java.util.*" %>
<jsp:useBean id="formHandler" class="user.FormBean" scope="request"/>
<jsp:setProperty name="formHandler" property="*" />

<TITLE>FSMO - (Placement Input Screen)</TITLE>
<LINK href="styles/style.css" rel="stylesheet" type="text/css">
<H2>Create New Placement</H2>

<%//Formbean DD=new FormBean();%>

<FORM action='process.jsp' method='POST'>
<TD>Enter Date of Placement :<br><INPUT size="10" maxlength="10" type="text" name="DOP" value=<%=formHandler.getDATEOFPLACEMENT()%>></TD>
<TD><query ropDown>Facility</query ropDown></TD>

<strong>Child Data</strong>
<TD>Enter Child's First Name :<br> <INPUT size="10" maxlength="20" type="text" name="CFNAME" value=<%=formHandler.getCFNAME()%>></TD>
<TD>Enter Child's Last Name :<br> <INPUT size="10" maxlength="30" type="text" name="CLNAME" value=<%=formHandler.getCLNAME()%>></TD>
<TD>Enter SS# : <br> <INPUT size="10" maxlength="9" type="text" name="CSSN"value=<%=formHandler.getSSN()%>> </TD>
<TD><query ropDown>Race</query ropDown></TD><TD></TD>

public void queryRace() throws JspException, IOException
stmt= con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM RACE GROUP BY RACE");
pageContext.getOut().print("Select Race:<br> ");
pageContext.getOut().print("<select name=RACEID>");int i=8;
while (
{ int RaceID = rs.getInt("RACEID");
String Race = rs.getString("RACE");
if (RACEID !="7")
{pageContext.getOut().print("<option SELECTED value=" + PARAM[i][i+1] + " size='10'>" + PARAM[i][i]+ " </option>");}
else{pageContext.getOut().print("<option value=" + PARAM[i][i+1] + " size='10'>" + PARAM[i][i]+ " </option>");}

catch(Exception e) { pageContext.getOut().print("<h1>Invalid Username/password</h1>" + e.getMessage());
throw new IOException(e.getMessage());}

I used a tag to call dropdown. Please help.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This question belongs in the JSP forum.

However, you might try changing the scope of your bean to "session", and then placing it in the session context before displaying the page. This way your data isn't lost when the page is displayed.

Consultant, Sima Solutions
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24187

Moving to the JSP forum.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Generating a Dropdown from a bean to a JSP