JSP
Source Code
Home > Source Code >JSP > Bean Scope
 
  Getting And Setting A Property Of A Bean  
 
 
  1. Object o = new MyBean();

  2.     try {

  3.         // Get the value of prop1

  4.         Expression expr = new Expression(o,"getProp1",new Object[0]);

  5.         expr.execute();

  6.         String s = (String)expr.getValue();

  7.    

  8.         // Set the value of prop1

  9.         Statement stmt = new Statement(o,"setProp1",new Object[]{"new string"});

  10.         stmt.execute();

  11.    

  12.         // Get the value of prop2

  13.         expr = new Expression(o,"getProp2",new Object[0]);

  14.         expr.execute();

  15.         int i = ((Integer)expr.getValue()).intValue();

  16.    

  17.         // Set the value of prop2

  18.         stmt = new Statement(o,"setProp2",new Object[]{new Integer(123)});

  19.         stmt.execute();

  20.    

  21.         // Get the value of prop1

  22.         expr = new Expression(o,"getProp3",new Object[0]);

  23.         expr.execute();

  24.         byte[] bytes = (byte[])expr.getValue();

  25.    

  26.         // Set the value of prop1

  27.         stmt = new Statement(o,"setProp3",new Object[]{new byte[]{0x12,0x23}});

  28.         stmt.execute();

  29.     } catch (Exception e) {

  30.     }

  31.    

  32.     public class MyBean {

  33.         // Property prop1

  34.         String prop1;

  35.         public String getProp1() {

  36.             return prop1;

  37.         }

  38.         public void setProp1(String s) {

  39.             prop1 = s;

  40.         }

  41.    

  42.         // Property prop2

  43.         int prop2;

  44.         public int getProp2() {

  45.             return prop2;

  46.         }

  47.         public void setProp2(int i) {

  48.             prop2 = i;

  49.         }

  50.    

  51.         // Property prop3

  52.         byte[] prop3;

  53.         public byte[] getProp3() {

  54.             return prop3;

  55.         }

  56.         public void setProp3(byte[] bytes) {

  57.             prop3 = bytes;

  58.         }

  59.     }
 
 
Date entered : 17th Feb 2007
Rating : No Rating
Accessed : 3526
Submitted by : javabill
 
0 comments have been posted for this Source Code.View Comments Here
 
Home > Source Code >JSP > Bean Scope
Copyright Visualbuilder.com 1999-2006
 
 
 

Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0