Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
JavaBeans
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Code example=== <syntaxhighlight lang=Java> package player; public class PersonBean implements java.io.Serializable { /** Properties **/ private boolean deceased = false; private List list; /** Property "name", readable/writable. */ private String name = null; /** No-arg constructor (takes no arguments). */ public PersonBean() { } public List getList() { return list; } public void setList(final List list) { this.list = list; } /** * Getter for property "name". */ public String getName() { return name; } /** * Setter for property "name". * * @param value */ public void setName(final 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; } } </syntaxhighlight> '''<u><code>TestPersonBean.java</code></u>''': <syntaxhighlight lang=Java> import player.PersonBean; /** * Class "TestPersonBean". */ public class TestPersonBean { /** * Tester method "main" for class "PersonBean". * * @param arguments */ public static void main(final String[] arguments) { final PersonBean person = new PersonBean(); person.setName("Bob"); person.setDeceased(false); person.setList(new ArrayList()); // Output: "Bob [alive]" System.out.print(person.getName()); System.out.println(person.isDeceased() ? " [deceased]" : " [alive]"); } } </syntaxhighlight> <syntaxhighlight lang="xml"> <jsp:useBean id="person" class="player.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> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)