• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Generating a Dropdown from a bean to a JSP

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

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="*" />

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

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

<FORM action='process.jsp' method='POST'>
<TABLE border="0" CELLPADDING=10 CELLSPACING=1 BGCOLOR="">
<TR>
<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>
</TR>
</TABLE>

<TABLE BORDER=1 RULES=NONE FRAME=BOX CELLPADDING=10 CELLSPACING=1 BGCOLOR="">
<strong>Child Data</strong>
<TR>
<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>

BEAN
public void queryRace() throws JspException, IOException
{
try
{con=DriverManager.getConnection(host,userName,passWord);
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 (rs.next())
{ 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>");}
}
pageContext.getOut().print("</select>");

con.close();
}
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.

Thanks
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the JSP forum.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stewart,

Two tips that should help you to get assistance more easily:
1.) If you're going to post more than a line or two of code, wrap the code in UBB tags. There is button in the edit screen that will help you to generate the tags. The UBB Code tags will preserve your indenting, making it much easier for us to read it.

2.) At the bottom left of the edit screen there is a checkbox for disabling smilies. This will keep your Dropdown tags from grinning at us.

Your bean is bound to 'request' scope. That means it will last for the duration of only one request. Subsequent requests will each create their own instance of the bean.

If you're interested, I have a DynamicSelectList example app at:
http://simple.souther.us/not-so-simple. It shows one way of dealing with select lists.
[ June 14, 2005: Message edited by: Ben Souther ]
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic