Announcement Announcement Module
Collapse
No announcement yet.
null argument to setter? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • null argument to setter?

    Could someone explain why the setWleDao() method was being called with a null argument in the following code? The only way I could get it to work (setting the wleDao field) was to change the bean wiring to use a constructor. I was under the impression that it should work with a setter or a constructor.

    Code:
    public class
    SignInCtlr extends SimpleFormController {
        private WleDao      wleDao;
    
        public
        SignInCtlr(WleDao wleDao) {
            setCommandClass(SignInFrmData.class);
            this.wleDao = wleDao;
        }
    
        protected ModelAndView
        onSubmit(Object cmd, BindException errs) throws Exception {
            SignInFrmData sifd = (SignInFrmData) cmd;
    
            String view = sifd.getView();
    
            sifd.setWle(wleDao.getWaitlistEntries());
    
            return(new ModelAndView(view, "sifd", sifd));
        }
    
        public void
        setWleDao(WleDao wledao) {
            this.wleDao = wleDao;
        }
    }
    This is the config from the xml file:

    Code:
        <bean id="signInCtlr"
            class="SignInCtlr">
            <constructor-arg>
                <ref bean="wleDao" />
            </constructor-arg>
            <property name="sessionForm">
                <value>true</value>
            </property>
            <property name="commandName">
                <value>sifd</value>
            </property>
            <property name="commandClass">
                <value>SignInFrmData</value>
            </property>
            <property name="validator">
                <ref bean="signInValidate" />
            </property>
            <property name="formView">
                <value>signInView</value>
            </property>
            <property name="successView">
                <value>signInFrmDataView</value>
            </property>
    <!--
            <property name="wleDao">
                <ref bean="wleDao" />
            </property>
    -->
        </bean>

  • #2
    Simple case typo. "wledao" should be "wleDao". Try:
    Code:
    setWleDao&#40;WleDao wleDao&#41; &#123;
            this.wleDao = wleDao;
    &#125;

    Comment


    • #3
      Duh. I should have caught that!

      Many thanks.

      Comment


      • #4
        No probs. A good IDE like Eclipse can pick this up - can even configure it to be an error.

        Comment


        • #5
          I have a non-standard coding style that Eclipse doesn't support; I like to put the method's types and modifiers on the line above it;
          Code:
          public final static String
          xyzzy&#40;&#41; &#123;
              return&#40;"a string"&#41;;
          &#125;
          If it wasn't for that I'd use it.

          Comment


          • #6
            I have a non-standard coding style that Eclipse doesn't support...If it wasn't for that I'd use it.
            It may not auto-format that way, but it shouldn't automatically reformat it on you. Having moved from UltraEdit well over a year ago myself, I'd now never go back. I'd recommend Eclipse (or similar - I've heard great things about IntelliJ IDEA) as an essential tool.

            Comment

            Working...
            X