cancel
Showing results for 
Search instead for 
Did you mean: 

how to expose custom spring beans to the jsf context

mike_kukla
Champ in-the-making
Champ in-the-making
Throughout the Alfresco faces-config.*.xml files, one finds expressions like
this:  <value>#{NodeService}</value> or  <value>#{SearchService}</value>.

In other words, beans configured in and managed by Spring are somehow made
accessible to the JSF configuration/context.

For example, in faces-config-beans.xml:

<managed-bean>
   <managed-bean-name>MultilingualManageDialog</managed-bean-name>
   <managed-property>
      <property-name>nodeService</property-name>
   <value>#{NodeService}</value>
   </managed-property>
   …
</managed-bean>

Can any one explain how one would do the same thing for a **custom** spring bean:
i.e., configure a custom bean in spring and then "expose" it to the JSF context,
something like this:

In some custom-bean-context.xml
<bean id="MyCustomSpringBean" class="…"/>

In faces-config-custom.xml

  <managed-bean>
      <managed-bean-name>MyCustomManagedBean</managed-bean-name>
       <managed-property>
         <property-name>mySpringBean</property-name>
         <value>#{MyCustomSpringBean}</value>
      </managed-property>
      …
   </managed-bean>
  
My apologies if the solution to this is obvious, or if this question has already been posed and answered.
I'm new to Alfresco and still learning.

Mike Kukla
Buffalo, NY
1 REPLY 1

mike_kukla
Champ in-the-making
Champ in-the-making
For the benefit of all those who in the days to come may alight upon this thread, 
I found shortly after posting my initial question that it is trivial to expose custom
spring beans to the jsf context.

One just does what the Alfresco source itself does i.e.,  one could do this in faces-config-custom.xml:

<managed-bean>
      <managed-bean-name>DocumentPropertiesDialogBean</managed-bean-name>
      <managed-bean-class>someco.jsf.beans.dialogs.DocumentPropertiesDialogBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>browseBean</property-name>
         <value>#{BrowseBean}</value>
      </managed-property>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>documentReferenceDataBean</property-name>
         <value>#{DocumentReferenceDataBean}</value>
      </managed-property>

      <managed-property>
         <property-name>contentCreationDialogStackDepth</property-name>
         <value>5</value>
      </managed-property>
   </managed-bean>

where DocumentReferenceDataBean is a Spring managed bean.

What lies behind this magic is, I believe, is the JSF's  DelegatingVariableResolver.

For those looking for a little explanation, Sections  15.3.1- 15.3.2  of http://static.springsource.org/spring/docs/2.5.6/reference/web-integration.html provide a brief, but  useful explanation of the basics of Spring-JSF integration.