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 > Re: soooo many ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 1335 of 1403
Post > Topic >>

Re: soooo many questions!

by Vince <info@[EMAIL PROTECTED] > Dec 27, 2007 at 05:17 PM

soldier.coder wrote:
> 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;
> 	}
> 
> }

Hi Soldier

it seems like you've got the wrong approach on what Java can do for you 
in terms of Web Application.

What you're producing in your code is almost not maintainable and 
secondly it should rather be part of a servlet than a bean. Have a look 
in the internet what you can find about MVC (Model, View, Controller). 
There are some very good frameworks out there (JSF, Struts etc) that 
will help you create HTML content without having to struggle putting and 
assembling html strings together.

The fundamentals of MVC is actually to separate the View (JSP) from the 
  Model (Data) and the Logic (Controller). What again means that your 
Controller will access - through JAVA - the Data on the one side and 
provide it to the View (JSP)on the other side.

In this context the mentioned JavaBeans will be used to translate as 
example the data from a database to a Java Object. Which again will be 
used in the JSP to display the data.

The separation makes pretty much sense since we also reached the age of 
web 2.0. Per se, the age of designing pages completely with CSS 
(Cascaded Style Sheets). Imagine a project where the designer doesn't 
need to be aware of any programing language, and on the counter part the 
developer doesn't need to know anything about design. While again the DB 
administrator doesn't need to be an expert in either of the previous 
mentioned skills... That's what MVC is for...

Wish you a lot of success re-establi****ng yourself as a developer...

Vince

-- 
Posted via a free Usenet account from http://www.teranews.com
 




 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 Wed Dec 3 23:42:16 CST 2008.