Results 1 to 2 of 2

Thread: DI for abstract classes failing

  1. #1
    Join Date
    Sep 2004
    Location
    London
    Posts
    4

    Default DI for abstract classes failing

    I am having trouble wiring up a bean hierarchy. I have an abstract template class which looks like:

    Code:
     public abstract class ClaimAction extends DefaultAction {
    
        private ClaimManager claimManager;
    
        public void setClaimManager(ClaimManager claimManager) {
            this.claimManager = claimManager;
        }
    
        public void execute() {
            //blah blah some code here
            claimManager.doSomething(); 
            showClaim();
    
        }
    
        private Claim loadClaim(long claimID) {
            return 
        }
    
        /**
         * Subclasses implement this 
         */
        protected abstract ActionForward showClaim();
    }
    And a concrete subclass:

    Code:
    public class ClaimSummaryAction extends ClaimAction {
    
        protected ActionForward showClaim() {
            //show it
        }
    }
    When I try to run the showClaim method on ClaimSummaryAction I get a nullpointer in the superclass as the claimManager is not set.

    My config file looks like:

    Code:
    <bean id = "claimAction" class="com.***.claim.ClaimAction" abstract="true" >
        <property name="claimManager"><ref bean="claimManager" /></property>
    </bean>
    
    <bean id = "claimSummaryAction" parent="claimAction" class="com.***.claim.ClaimSummaryAction" />
    
    <bean id = "claimDAO" class="com.***.claim.ClaimDAO">
        <property name="sessionFactory"><ref bean="mySessionFactory"/></property>
    </bean>
    I need both the abstract class and the subclass to be able to access the claimManager. I realise I must be doing something wrong here, any help much appreciated.

  2. #2
    Join Date
    Aug 2004
    Location
    Madrid, Spain
    Posts
    25

    Default DI for abstract classes failing

    I think you just need to omit the class attribute from your abstract parent bean.

    HTH,
    Fernando

Similar Threads

  1. Avoiding UI-centric Domain Classes
    By dhainlin in forum Web
    Replies: 5
    Last Post: Mar 27th, 2006, 01:16 PM
  2. Replies: 1
    Last Post: May 28th, 2005, 06:28 AM
  3. Replies: 5
    Last Post: May 11th, 2005, 04:27 PM
  4. Replies: 1
    Last Post: May 5th, 2005, 01:30 AM
  5. Command classes and actions
    By stevecnz in forum Web
    Replies: 1
    Last Post: Oct 6th, 2004, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •