1

I want to map this bean in my facesconfig.xml

public class VisualizationBean {

    private BitSet results;

    public BitSet getResults() {
        return results;
    }

    public void setResults(BitSet results) {
        this.results = results;
    }

}

As I saw in some articles and some examples, it is possible to initialize maps or other fields, but I can't figure out how to initialize this fiel. I guess something similar to

 <managed-bean>
        <managed-bean-name>visualizationBean</managed-bean-name>
        <managed-bean-class>path.bean.VisualizationBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>results</property-name>
            <map-entries>
                <map-entry>
                    <key>true</key>
                    <value>6</value>
                </map-entry>
                <map-entry>
                    <key>false</key>
                    <value>12</value>
                </map-entry>
                <map-entry>
                    <key>false</key>
                    <value>24</value>
                </map-entry>                
            </map-entries>
        </managed-property>        
    </managed-bean>

But htis is not correct. Any help?? Thanks in advance

jmj
  • 237,923
  • 42
  • 401
  • 438
Blanca Hdez
  • 3,513
  • 19
  • 71
  • 93

1 Answers1

1

You can't. The BitSet doesn't implement Map and JSF doesn't provide facilities to preset other managed property data structures than List or Map.

You have basically 2 options:

  1. Use a Map<Object, Boolean> instead (note that you need to inverse the keys/values in your faces-config.xml; keys are supposed to be unique!)

  2. Fill the BitSet yourself during bean's (post)construction based on some other external file, like a .properties file.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Ok, thanks for your explanation. Can I initialize using an external file, as you suggest, in the same faces-config?? – Blanca Hdez Mar 01 '11 at 13:20
  • Can I initialize using an external file, as you suggest, in the same faces-config?? – Blanca Hdez Mar 01 '11 at 14:04
  • 1
    No. Just put the file in classpath and obtain it by `Class#getResourceAsStream()`. Best what `faces-config.xml` can offer you is the ability to specify the path/name of the file in question. – BalusC Mar 01 '11 at 14:08