How to use set, get basic and nested properties for Spring framework

By: Saravanan Emailed: 1767 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

In this tutorial we are going to see how to use set, get basic and nested properties for spring frame work. set and get properties are done using the setPropertyValue(s) getPropertyValue(s) methods that both come with a couple of overloaded variants.

Examples of properties

Expression:

*name
*account.name
*account[2]

name Indicates the property name corresponding to the methods getName() or isName() and setName()

account.name Indicates the nested property name of the property account corresponding e.g. to the methods getAccount().setName() or getAccount().getName()

account[2] Indicates the third element of the indexed property account. Indexed properties can be oftype array, list or other natural ordered collection

we can some examples of working with the BeanWrapper to get and set properties.

Consider the following two classes:

public class Company
{
private String name;
private Employee MD;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
public Employee getMD()
{
return this.MD;
}
public void setMD(Employee MD)
{
this.MD = MD;
}
}

public class Employee
{
private float salary;
public float getSalary()
{
return salary;
}
public void setSalary(float salary)
{
this.salary = salary;
}
}


Now we are going to see how to retrieve and manipulate some of the properties of
instantiated: Companies and Employees

Company c = new Company();
BeanWrapper bwComp = BeanWrapperImpl(c);

// setting the company name...
bwComp.setPropertyValue("name", "Company Inc.");

// we can also be done like this:
PropertyValue v = new PropertyValue("name", "Company Inc.");
bwComp.setPropertyValue(v);

// now we can create the director and tie it to the company:
Employee mathew = new Employee();
BeanWrapper bwmathew = BeanWrapperImpl(mathew);
bwJim.setPropertyValue("name", "mathew Hyden");
bwComp.setPropertyValue("MD", mathew);

// retrieving the salary of the MD through the company
Float salary = (Float)bwComp.getPropertyValue("MD.salary");


Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Saravanan
Converting properties using PropertyEditors and Other Spring features worth mentioning
How to create an array and method in JSP
inheritance in Java
Use List, Set, SortedSet, LinkedHashSet, Map, LinkedHashMap in java
cloneable in Java
Java program for Associate keys with values
Java code for Enumeration and using java.lang.reflect.Array
Insert an element in Array, Search and Sort Array by using java program
Type Casting in Java
How to initialize an Array and how to copy the array
Simple java program to add an element to specified index of Java ArrayList
How to use set, get basic and nested properties for Spring framework
How to access instance from an inner class and accessing outer class variables in java
How to use and access the inner class in java
Java program for Map

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
A Serialization Example in Java
indexOf( ) and lastIndexOf( ) in Java
The java Buzzwords
Student marks calculation program in Java
Handling Fractions in Java
Calculate average sale of the week in Java
Write to a file in Java - Sample Program
How to create an array and method in JSP
How to use set, get basic and nested properties for Spring framework
A Tutorial on importing packages in Java
do-while - Iteration in java
Increment and Decrement Operator
Character Arrays
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Most Emailed Articles (in Java)
Converting a number into its equalant value in words in Java
java.lang.reflect package
Disadvantages of using Native methods in Java
What is UCS? What is ISO 10646?
Generating Your Key Pair example using keytool in Java
Operator Precedence in Java
PushbackReader sample program in Java
concat(), replace(), and trim() Strings in Java
instanceof sample program in Java
Use of - new - in Java
The Benefits of OOP
Increment and Decrement Operator
Characters in java
The continuing Revolution of java
Why java is important to the Internet