Set a Map (or Object) against a Managed Bean property using faces-config.xml


Code 1: XSP Markup for test harness...

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.ibm.com/xsp/core xsdxp://localhost/xsp~core.xsd">
	
	<xp:repeat id="repeat1" rows="30"
		value="#{javascript:myBean.getMap().entrySet()}"
		indexVar="i" var="mapEntry" first="0">
		<xp:text escape="false" id="computedField2">
			<xp:this.value>
				<![CDATA[#{javascript:
					"<div style=\"padding:4px\">" +
						"<b>#" + i + "</b>" +
							" key=" + mapEntry.key + 
							" value=" + mapEntry.value + 
					"</div>"
				}]]>
			</xp:this.value>
		</xp:text>
	</xp:repeat>

</xp:view>

Code 2: faces-config.xml Declarations...

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
  
  <managed-bean>
    <managed-bean-name>myBean</managed-bean-name>
    <managed-bean-class>foo.bar.MyBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
    	<property-name>map</property-name>
    	<value>#{myMap}</value>
    </managed-property>
  </managed-bean>
  
  <managed-bean>
    <managed-bean-name>myMap</managed-bean-name>
    <managed-bean-class>java.util.HashMap</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <map-entries>
   		<value-class>java.lang.Integer</value-class>
   		<map-entry>
   			<key>One</key>
   			<value>1</value>
   		</map-entry>
   		<map-entry>
   			<key>Two</key>
   			<value>2</value>
   		</map-entry>
   		<map-entry>
   			<key>Three</key>
   			<value>3</value>
   		</map-entry>
    </map-entries>
  </managed-bean>
  
  <!--AUTOGEN-START-BUILDER: Automatically generated by IBM Lotus Domino Designer. Do not modify.-->
  <!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>

Code 3: MyBean.java Managed Bean code...

package foo.bar;

import java.util.HashMap;

/**
 * @author Tony McGuckin, IBM
 */
public class MyBean {

	private HashMap<String, Integer> _map;
	
	// ---------------------------------------------------------
	
	public MyBean() {}
	
	// ---------------------------------------------------------
	
	public void setMap(HashMap<String, Integer> map){
		this._map = map;
	}
	
	// ---------------------------------------------------------
	
	public HashMap<String, Integer> getMap(){
		return _map;
	}
}

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...