Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > soooo many ques...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1335 of 1372
Post > Topic >>

soooo many questions!

by "soldier.coder" <geekprogrammer.ed@[EMAIL PROTECTED] > Dec 20, 2007 at 02:06 PM

Hello kind professional java programmers!

I am a former soldier trying to re-establish himself in the civilian
world and I have so many questions.  First of all, what does it really
take to create a java bean that does anything?  A friend of mine who
is exploring servlets was very shocked to discover how much work it
takes to create a dropdown HTML menu in Java, so I thought I would
have a go at it.

I thought my javabean should have properties for the:
 name of the HTML dropdown menu,
 a default <option> tag (to handle when user selects nothing),
 a size,
 and an SQL statement that when executed would yield 2 columns, the
first being the non-zero id of the row we got             from the
database(for the "value" part of an option tag), and the second column
being the displayed part of the
option tag.

Anyway, I haven not handled getting the data from database yet, but
what else must i do or include to make it a bean, and how then would I
use it for a bean inside a JSP page?

/
*******************************************************************************************************************
 *
 * DropDownHTML
 *
 *   This code creates a serializable object (that might someday
become a Java Bean) that, given an SQL statement,
 * and a connection to the appropriate database, will produce a
dropdown menu in HTML, as a string via the toString
 * method.
 
*******************************************************************************************************************/


im****t java.io.*;		// we will sup****t serialization


public class DropDownHTML implements Serializable
{
	private String	SqlStatement; 		// SQL for 2 columns: first column is
value part, second column is display part
	private String 	Name; 				// html name for the the drop down menu
	private String 	HandleNoChoice; 	// if they choose nothing, this will
be displayed -- always has 0 value
	private int    	Size; 				// size of the display in rows, not the
number of actual rows
	private boolean	SelectMoreThanOne;	// can user choose more than one?
	transient int 	nRows;

	public DropDownHTML()
	{
		this.SqlStatement = new String("select * from categories");
		this.Name	= new String("example_drop_down");
		this.HandleNoChoice = new String("<option selected value=\"0\">No
selection has been choosen</option>");
		this.Size = 4;
		this.SelectMoreThanOne = false;
	}

	public DropDownHTML(String mySQLStatement,String myDropDownName, int
size,boolean single  )
	{
		this.SqlStatement = new String(mySQLStatement);
		this.Name	= new String(myDropDownName);
		this.HandleNoChoice = new String("<option selected value=\"0\">No
selection has been choosen</option>");
		this.Size = size;
		this.SelectMoreThanOne = single;
	}

	public String toString()
	{
		String selectMoreThanOne = new String ((this.SelectMoreThanOne) ?
"MULTIPLE " : "SINGLE ");

		String selectHTML = new String("<SELECT ") + selectMoreThanOne +
"SIZE=\'" + this.Size + "\' name=\'" + this.Name + "\'>";
		String endSelectHTML = new String("</SELECT>");
		return selectHTML + endSelectHTML;
	}

}
 




 2 Posts in Topic:
soooo many questions!
"soldier.coder"  2007-12-20 14:06:03 
Re: soooo many questions!
Vince <info@[EMAIL PRO  2007-12-27 17:17:36 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 22:50:06 CDT 2008.