Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: HELP IoC problem

  1. #1

    Default HELP IoC problem

    Hello All,

    Please advise I cannot access the exchangeCodes properties while I am able to access this one...<property name="areaCode" value="205"/>

    when I try to get the exchangeCodes I get null values.

    Thanks
    Richard

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
        <bean id="SignupController" class="xxx.xxx.xxx.controller.SignupWizardController">
            <property name="pages">
                <list>
                    <value>signup-start-phoneplans</value>
                    <value>signup-step1-phonenumber</value>
                    <value>signup-step2-phoneadapter</value>
                </list>
            </property>
            <property name="phonePlansDao">
                <ref bean="PhonePlansDao"/>
            </property>
            <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>sc</value></property>
            <property name="commandClass"><value>xxx.xxx.xxx.command.SignupCommand</value></property>
            <property name="countries" >
                <set>
                    <bean id="us" class="com.voxsant.commons.constants.Country">
                        <property name="country" value="United States"/>
                        <property name="stateProvinceRegion">
                            <set>
                                <bean id="alabama" class="xxx.xxx.xxx.constants.StateProvinceRegion">
                                    <property name="stateProvinceRegion" value="Alabama"/>
                                    <property name="areaCodes">
                                        <set>
                                            <ref bean="ac205"/>
                                        </set>
                                    </property>
                                </bean>
                            </set>
                        </property>
                    </bean>
                    <bean id="canada" class="com.xxx.xxx.constants.Country">
                        <property name="country" value="Canada"/>
                    </bean>
                </set>
            </property>
        </bean>
        <bean id="ac205" class="com.xxx.xxx.constants.AreaCode">
            <property name="areaCode" value="205"/>
            <property name="exchangeCodes" >
                <set>
                    <value>267 (Bessemer)</value>
                    <value>282 (Jasper)</value>
                    <value>304 (Dora)</value>
                    <value>316 (Centrevl)</value>
                    <value>352 (Leeds)</value>
                    <value>386 (Gardendale)</value>
                    <value>390 (Graysville)</value>
                    <value>409 (Tuscaloosa)</value>
                    <value>419 (Alabaster)</value>
                    <value>453 (Birmingham)</value>
                    <value>683 (Pinson)</value>
                    <value>742 (Livingston)</value>
                </set>
            </property>
        </bean>
    
    </beans>

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Strange - can you please make sure that your configuration is correct (maybe with a very small example) and if possible, turn on logging to make sure the conversion works.
    I see no reason why the exchangeCodes set should work.
    Btw, it's recommended to externalize the codes (maybe to a properties file) - you can convert it to a set if you still want to (declare only keys but no values).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3

    Default

    Hi Costin,

    I am hoping that you can show a sample on how to do this..

    Btw, it's recommended to externalize the codes (maybe to a properties file) - you can convert it to a set if you still want to (declare only keys but no values).

    Thanks
    Richard

  4. #4
    Join Date
    Nov 2005
    Location
    Christchurch, New Zealand
    Posts
    17

    Default

    It's discussed (with an example) in the spring documentation here:

    http://static.springframework.org/sp...lderconfigurer

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    johnny beat me to it. Besides the reference documentation, you can also see the samples included in Spring distribution.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6

    Question

    Hi Costin/Guys,

    I hope somebody can give me a good example on how I can externalized these values, I am currently using a property file for my datasource values but I cannot visualize how different will it be if I put these values...

    Code:
    <value>267 (Bessemer)</value>
                    <value>282 (Jasper)</value>
    in a property file. I think the problem is in the <set>

    Code:
    <property name="exchangeCodes" >
                <set>
                    <value>267 (Bessemer)</value>
                    <value>282 (Jasper)</value>
    part of the injection. If I use a property file i will still be using the <set> element right?

    Thanks
    Richard

  7. #7
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    <property name="exchangeCodes">
    <bean class="org.springframework.beans.factory.config.Pr opertiesFactoryBean>
    <property name="location" value="classpath:myValues.properties"/>
    </bean>
    </property>

    while your myValues property can contain something like:
    267 = Bessemer
    282 = Jasper
    If you want to have only keys and your are not interested into a map you can use this format:

    267 Bessemer =
    282 Jasper =
    which will result in map just with keys (and empty values).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  8. #8

    Default

    Hi Costin,

    In here you have assumed that exchangeCodes is of java.util.Set datatype?

    Code:
    <property name="exchangeCodes">
    <bean class="org.springframework.beans.factory.config.Pr opertiesFactoryBean>
    <property name="location" value="classpath:myValues.properties"/>
    </bean>
    </property>
    thanks
    Richard

  9. #9
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    No, I have assumed that exchangeCodes is of type map (which is a parent of java.util.Properties). You can do a simple conversion from Map to Set if you want inside the setter or inside your init method.
    Moreover, if you can also do your own factorybean or you can even call the keySet method on the returned map (you can do this from Spring XML).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  10. #10

    Default

    Hi Costin,

    I think I want to this but please please elaborate further i dont have a clue what you mean.

    Code:
    you can even call the keySet method on the returned map (you can do this from Spring XML).
    I tried this but spring throws an exception...

    Code:
        private  Map exchangeCodes ;
    
        public Set getExchangeCodes() {
            return exchangeCodes.keySet();
        }
    that the getter method is invalid since the type declared for exchangeCodes is interface Map.

    Thanks
    richard

Posting Permissions

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