Announcement Announcement Module
Collapse
No announcement yet.
Abstract classes and bean definitions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Abstract classes and bean definitions

    Iím new to Spring and have run into a problem with some of my bean definitions. I have the following classes:

    Code:
    public class User {
    	
       private UserType userType = null;
    
    	public User (UserType userType) {
    		this.userType = userType;
    	}	
            public UserType getUserType() {
    		return userType;
    	}
    	public void setUserType(UserType type) {
    		userType = type;
    	}
    }
    
    public abstract class UserType {
    	//some abstract methods;
    }
    public abstract class Customer extends UserType {
    	//some abstract methods;
    }
    public class Staff extends UserType {
    	public Staff() {}	
    }
    public class Business extends Customer {
    	public Business() {}	
    }
    public class Individual extends Customer {
    	public Individual () {}	
    }
    I was hoping to use the User object on my JSPís so that I can access some common attributes in the following manner:
    Code:
    <spring&#58;bind path="user.userType.someCommonAttribute">
    but Iím running into problems because UserType is abstract.

    I read the Spring reference guide section on Abstract and Child Bean Definitions, but Iím not sure how to define the User and UserType beans since UserType is an abstract class and also an attribute of User. I was looking into bean factories, but Iím not sure if that is the right approach. I would think this would be a fairly common issue, but didnít have any luck finding answers when I searched the forums. Does anyone have any advice? Thanks in advance.

  • #2
    have a look in the docs regarding Abstract and child bean definitions

    Comment

    Working...
    X