GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||
GeezerVison is showing en.wikipedia.org — JavaBeans - Wikipedia (Redirected from JavaBean) Not to be confused with Enterprise JavaBeans.
In computing based on the Java Platform, JavaBeans is a technology developed by Sun Microsystems and released in 1996, as part of JDK 1.1. The 'beans' of JavaBeans are classes that encapsulate one or more objects into a single standardized object (the bean). This standardization allows the beans to be handled in a more generic fashion, allowing easier code reuse and introspection. This in turn allows the beans to be treated as software components, and to be manipulated visually by editors and IDEs without needing any initial configuration, or to know any internal implementation details. As part of the standardization, all beans must be serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods. Features
Advantages
Disadvantages
JavaBeans APIThe JavaBeans functionality is provided by a set of classes and interfaces in the
JavaBean conventionsIn order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect Java Beans. The required conventions are as follows:
Code examplepackage org.wikipedia.players; import java.io.Serializable; import java.util.List; public class PersonBean implements Serializable { // Properties private boolean deceased = false; private List<String> list; // Property "name", readable/writable. private String name = null; // No-arg constructor (takes no arguments). public PersonBean() { } public List<String> getList() { return list; } public void setList(List<String> list) { this.list = list; } /** * Getter for property "name". */ public String getName() { return name; } /** * Setter for property "name". * * @param value */ public void setName(String value) { this.name = value; } /** * Getter for property "deceased" * Different syntax for a boolean field (is vs get) */ public boolean isDeceased() { return deceased; } /** * Setter for property "deceased". * @param value */ public void setDeceased(boolean value) { deceased = value; } }
package org.wikipedia.players; import java.util.ArrayList; import org.wikipedia.players.PersonBean; /** * Class "TestPersonBean". */ public class TestPersonBean { /** * Tester method "main" for class "PersonBean". * * @param arguments */ public static void main(String[] args) { PersonBean person = new PersonBean(); person.setName("Bob"); person.setDeceased(false); person.setList(new ArrayList<>()); // Output: "Bob is [alive]" System.out.printf("%s is %s%n", person.getName(), person.isDeceased() ? " [deceased]" : " [alive]"); } } <jsp:useBean id="person" class="org.wikipedia.players.PersonBean" scope="page"/> <jsp:setProperty name="person" property="*"/> <html> <body> Name: <jsp:getProperty name="person" property="name"/><br/> Deceased? <jsp:getProperty name="person" property="deceased"/><br/> <br/> <form name="beanTest" method="POST" action="testPersonBean.jsp"> Enter a name: <input type="text" name="name" size="50"><br/> Choose an option: <select name="deceased"> <option value="false">Alive</option> <option value="true">Dead</option> </select> <input type="submit" value="Test the Bean"> </form> </body> </html> See alsoReferences
External linksHidden categories:
| ||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |