JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes

lifestyleappsios windows appcolt educationappsios
 31 December 18:00   

    



    



    

(Continued from antecedent part...)

    



    

In this section, let s attending at some of the basal rules about ambience and getting

    

JavaBean properties:

    



        

  • The setProperty aspect haveto be accurate by at atomic one set adjustment in the

        

    JavaBean class.

        



  •     

  • The set adjustment name haveto be the acreage name with the first lower case letter

        

    being translated to high case, and prefixed with "set". For example, "setAuthor"

        

    is a acceptable adjustment name to abutment the setProperty activity aspect for acreage

        

    name "author".

        



  •     

  • The acknowledgment blazon of the set adjustment should be void.

        



  •     

  • The set adjustment should yield alone one ascribe parameter.

        



  •     

  • If there are assorted set methods, there haveto be one that takes Cord as the

        

    input constant type, and this will be the one to be acclimated by the setProperty action

        

    element.

        



  •     

  • If there is alone one set method, the ascribe constant blazon should be a primitive

        

    type.

        



  •     

  • The get adjustment name haveto be the acreage name with the first lower case letter

        

    being translated to high case, and prefixed with "get". For example, "getAuthor"

        

    is a acceptable adjustment name to abutment the getProperty activity aspect for property

        

    name "author".

        



  •     

  • The get adjustment should yield no ascribe parameter.

        



  •     

  • The acknowledgment blazon of the get adjustment can be Cord or any archaic type.

        



  •     

  • JavaBean proproty names haveto be started with a lower case letter.

        



  •     



    



    

To validate the aloft rules, I wrote the afterward sample JavaBean class:

    

 

    

/**

    

* DemoBean.java

    

* Absorb (c) 2003 by Dr. Yang. All rights reserved.

    

*/

    

package ;

    

public chic DemoBean {

    

clandestine Cord columnist = "";

    

clandestine int calculation = 0;

    

clandestine boolean cachet = true;

    

clandestine Cord absolute = "1";

    

clandestine Cord admeasurement = "2";

    

accessible abandoned setAuthor(String a) {

    

columnist = a;

    

}

    

accessible Cord getAuthor() {

    

acknowledgment author;

    

}

    

accessible abandoned setCount(int c) {

    

calculation = c;

    

}

    

accessible int getCount() {

    

acknowledgment count;

    

}

    

accessible abandoned setStatus(boolean s) {

    

cachet = s;

    

}

    

accessible boolean getStatus() {

    

acknowledgment status;

    

}

    

accessible abandoned setTotal(int t) {

    

absolute = "int: "+t;

    

}

    

accessible abandoned setTotal(double t) {

    

absolute = "double: "+t;

    

}

    

accessible Cord getTotal() {

    

acknowledgment total;

    

}

    

accessible abandoned setSize(int s) {

    

admeasurement = "int: "+s;

    

}

    

accessible abandoned setSize(String s) {

    

admeasurement = "String: "+s;

    

}

    

accessible Cord getSize() {

    

acknowledgment size;

    

}

    

accessible abandoned setX(String x) {

    

columnist = x;

    

}

    

accessible Cord getY() {

    

acknowledgment author;

    

}

    

}

    



    



    

Compile this antecedent cipher with JDK 1.4.1, and archetype the chic book to the Bobcat chic path.

    

Remember to abundance the chic book beneath a sub agenda called as "".

    

 

    

>localj2sdk1.4.1injava DemoBean.java

    

>copy DemoBean.class

    

localjakarta-tomcat-4.1.18webapps
ootweb-infclasses



    



    

Now we are accessible to analysis this JavaBean with an JSP page, DemoBean.jsp:

    

 

    

<?xml version="1.0"?>

    

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">

    

<!-- DemoBean.jsp

    

Absorb (c) 2003 by Dr. Yang

    

-->

    

<html><body>

    

<jsp:useBean id="b">

    

<jsp:setProperty name="b" property="author" value="Nobody"/>

    

Line 1: columnist =

    

<jsp:getProperty name="b" property="author"/><br/>

    

<!-- <jsp:getProperty name="b" property="Author"/><br/> -->

    

<!-- <jsp:getProperty name="b" property="AUTHOR"/><br/> -->

    

<jsp:setProperty name="b" property="status" value="false"/>

    

Line 2: cachet =

    

<jsp:getProperty name="b" property="status"/><br/>

    

<jsp:setProperty name="b" property="count" value="5"/>

    

Line 3: calculation =

    

<jsp:getProperty name="b" property="count"/><br/>

    

<!-- <jsp:setProperty name="b" property="total" value="9"/> -->

    

Line 4: absolute =

    

<jsp:getProperty name="b" property="total"/><br/>

    

<jsp:setProperty name="b" property="size" value="14"/>

    

Line 5: admeasurement =

    

<jsp:getProperty name="b" property="size"/><br/>

    

<jsp:setProperty name="b" property="x" value=""/>

    

Line 6: admeasurement =

    

<jsp:getProperty name="b" property="y"/><br/>

    

</body></html>

    

</jsp:root>

    



    



    

Make abiding to run your Bobcat beneath JDK 1.4.1. Then accessible this JSP page with IE, you will get:

    

 

    

Line 1: columnist = Nobody

    

Line 2: cachet = false

    

Line 3: calculation = 5

    

Line 4: absolute = 1

    

Line 5: admeasurement = String: 14

    

Line 6: y =

    



    

(Continued on next part...)

    



    

 


Tags: lower, class, property, value, method, author, notes, public, string, tutorial, tutorials

 property, public, string, author, method, setproperty, getproperty, return, total, status, count, class, value, demobean, javabean, private, parameter, input, element, tomcat, lower, boolean, , < jsp, jsp getproperty, getproperty name, public void, jsp setproperty, setproperty name, property author, input parameter, method name, author <, public string, < <, size <, jsp page, property name, lower case, method should, private string, jsp getproperty name, jsp setproperty name, method should take, input parameter type, public void setsize, case letterbeing translated, public void settotal, lower case letterbeing, tutorial notes using, tutorials tutorial notes, notes using javabean, method name must, property name with, jstl tutorials tutorial,

Share JSP and JSTL Tutorials - Tutorial Addendum - Using JavaBean Classes:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  jsp