Results 1 to 6 of 6

Thread: addRequiredParameter

  1. #1
    Join Date
    Aug 2004
    Location
    Dallas, TX
    Posts
    6

    Default addRequiredParameter

    Both GenericFilterBean and HttpServletBean have a method named addRequiredProperty(String). Their javadoc reads:

    Subclasses can invoke this method to specify that this property (which must match a JavaBean property they expose) is mandatory, and must be supplied as a config parameter.
    Subclasses can invoke this method when and where? I am assuming a subclass must do it in init like this:

    Code:
    public void init(..) {
        addRequiredProperty("foo");
        addRequiredProperty("bar");
        super.init(..);
    }
    Anywhere else would be too late, and if super.init is not called, none of the parameters will be set into the properties at all. Is this right?

    Whatever the case, the javadocs should be more explicit as to when addRequiredProperty must be called, to avoid confusion with any of the other init* methods.

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Init is
    public final
    so a subclass can't actually overwrite it. Only a subclass constructor can reasonably call this method.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Dallas, TX
    Posts
    6

    Default

    Duly noted.

    I suggest changing:

    It is also possible for subclasses to specify required properties.
    To:

    It is also possible for subclasses to specify required properties through {@link #addRequiredProperty(String) addRequiredProperty} calls in the constructor.

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    I added something relatively similar, a couple of days ago...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Sep 2004
    Location
    Valencia, ES
    Posts
    92

    Default

    Hi,

    Are there any way to set the required properties through the application context?

    Something as:

    <property name="requiredProperty">
    <set>
    <value>foo</value>
    </set>
    </property>

    Regards.

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    You can use FilterToBeanProxy from the Acegi Security System. Some variant of this will probably make its way into Spring for v1.2...

Posting Permissions

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