Announcement Announcement Module
Collapse
No announcement yet.
reference to spring-bean in faces-config.xml doesn't work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • reference to spring-bean in faces-config.xml doesn't work

    Hello,

    I set up the variable resolver of spring in faces-config.xml:

    Code:
        <application>
            <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
        </application>
    I defined a dataSource bean in the spring-config:

    Code:
        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="java&#58;comp/env/jdbc/ora1"/>
        </bean>
    Now I'm trying to pass a reference to this bean in the faces-config.xml:

    Code:
        <managed-bean>
            <managed-bean-name>login</managed-bean-name>
            <managed-bean-class>web.jsf.LoginHandler</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
            <managed-property>
                <property-name>dataSource</property-name>
                <property-name>#&#123;dataSource&#125;</property-name>
            </managed-property>
        </managed-bean>
    Unfortunately, this doesn't work and I get a servlet exception:

    Code:
    500 Servlet Exception
    
    javax.faces.FacesException&#58; Can't instantiate class&#58; '#&#123;dataSource&#125;'.
    	at com.sun.faces.config.ManagedBeanFactory.getPropertyType&#40;ManagedBeanFactory.java&#58;377&#41;
    	at com.sun.faces.config.ManagedBeanFactory.setPropertiesIntoBean&#40;ManagedBeanFactory.java&#58;514&#41;
    	at com.sun.faces.config.ManagedBeanFactory.newInstance&#40;ManagedBeanFactory.java&#58;233&#41;
    	at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans&#40;ApplicationAssociate.java&#58;256&#41;
    	at com.sun.faces.el.VariableResolverImpl.resolveVariable&#40;VariableResolverImpl.java&#58;78&#41;
    	at org.springframework.web.jsf.DelegatingVariableResolver.resolveVariable&#40;DelegatingVariableResolver.java&#58;103&#41;
    	at com.sun.faces.el.impl.NamedValue.evaluate&#40;NamedValue.java&#58;125&#41;
    	at com.sun.faces.el.impl.ComplexValue.evaluate&#40;ComplexValue.java&#58;146&#41;
    	at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate&#40;ExpressionEvaluatorImpl.java&#58;243&#41;
    	at com.sun.faces.el.ValueBindingImpl.getValue&#40;ValueBindingImpl.java&#58;173&#41;
    	at com.sun.faces.el.ValueBindingImpl.getValue&#40;ValueBindingImpl.java&#58;154&#41;
    	at javax.faces.component.UIOutput.getValue&#40;UIOutput.java&#58;147&#41;
    	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue&#40;HtmlBasicInputRenderer.java&#58;82&#41;
    	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue&#40;HtmlBasicRenderer.java&#58;191&#41;
    	at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd&#40;HtmlBasicRenderer.java&#58;169&#41;
    	at javax.faces.component.UIComponentBase.encodeEnd&#40;UIComponentBase.java&#58;720&#41;
    	at javax.faces.webapp.UIComponentTag.encodeEnd&#40;UIComponentTag.java&#58;623&#41;
    	at javax.faces.webapp.UIComponentTag.doEndTag&#40;UIComponentTag.java&#58;546&#41;
    	at com.sun.faces.taglib.html_basic.InputTextTag.doEndTag&#40;InputTextTag.java&#58;524&#41;
    	at _jsp._login._index__jsp._jspService&#40;_index__jsp.java&#58;137&#41;
    	at com.caucho.jsp.JavaPage.service&#40;JavaPage.java&#58;63&#41;
    
    	at com.caucho.jsp.Page.pageservice&#40;Page.java&#58;579&#41;
    	at com.caucho.server.dispatch.PageFilterChain.doFilter&#40;PageFilterChain.java&#58;159&#41;
    &#91;...&#93;
    What is going wrong or what is missing?

    Regards
    Marten

  • #2
    I think you have an error in the JSF configuration. Your code should read:

    Code:
    <managed-property>
                <property-name>dataSource</property-name>
                <value>#&#123;dataSource&#125;</value>
            </managed-property>
    Notice that I have used the <value> tag to enclose the expression pointing to the Spring bean.


    Rob

    Comment


    • #3
      Thanks, I really didn't notice that although I read through it several times. It works fine now.

      Comment

      Working...
      X