java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips arrow JavaServer Pages arrow JSTL - Accessing compound bean properties
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
JSTL - Accessing compound bean properties E-mail
User Rating: / 28
PoorBest 

This sample shows you how to use <c:set> to set properties for compound beans, which are beans that contain references to other beans. In order to illustrate that approach, we'll create a compound bean Name which will be refered as a property of the other component Person. The name bean is a compound bean because it contains references to strings.

On initialization of person we set its name property to a bean object we create earlier. We use <c:set> action with EL expressions to modify the first and the last names directly from a person reference:

A bean to be used as a property:

package test;

public class Name {

  private String _first, _last;
  
  public void setFirst(String first) { _first = first; }
  public String getFirst() { return _first; }

  public void setLast(String last) { _last = last; }
  public String getLast() { return _last; }
}

A bean containing compound property:

package test;

public class Person {

  private Name _name;
  private String _email;
  
  public void setName(Name name) { _name = name; }
  public Name getName() { return _name; }

  public void setEmail(String email) { _email = email; }
  public String getEmail() { return _email; }
}

Page setting compound properties:

<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c' %>

<jsp:useBean id='name' class='test.Name'>
	<c:set target='${name}' property='first' value='John'/>
	<c:set target='${name}' property='last' value='Tate'/>
</jsp:useBean>

Bean initialization and property setting:

<jsp:useBean id='subscriber' class='test.Person'>
	<c:set target='${person}' property='name' value='${name}'/>
</jsp:useBean>


<html>
	...
	<c:out value='${person.name.first}'/>
	<c:out value='${person.name.last}'/>
	...
</html>


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.