1

I'm trying to integrate Spring 3 into a JSF 2 project. I registered the SpringBeanFacesELResolver in the faces-config.xml and I added two listeners to the web.xml:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

Most views and backing-beans are just working, but unfortunately, the javax.faces.event.PreRenderViewEvent ceased to function. I have been using this event to call a method in the backing-bean before the view is rendered:

<ui:define name="metadata">
    <f:event type="javax.faces.event.PreRenderViewEvent"
        listener="#{locationBean.preRenderView}" />
</ui:define>

With Spring 3 in place for bean creation, the preRenderView method is no longer called. I'd greatly appreciate any hint on what I might be doing wrong or missing!

Update:

In the same view, I'm trying to bind a parameter to a property of the backing-bean like this:

<ui:define name="metadata">
    <f:metadata>
        <f:viewParam name="id" value="#{locationBean.id}" label="id" />
    </f:metadata>
</ui:define>

This also used to work using "pure" JSF 2 but fails to do anything using Spring.

Community
  • 1
  • 1
cg.
  • 3,648
  • 2
  • 26
  • 30

1 Answers1

2

This is not really spring related but as far as I know the f:metadata tag has to be contained inside the template client and be inserted directly inside f:view. An example can be found at JSFAtWork. The link is in german but I hope the code examples are clear.

Your code would have to look like this

<ui:define name="metadata">
    <f:metadate>
        <f:event type="javax.faces.event.PreRenderViewEvent"
            listener="#{locationBean.preRenderView}" />
    </f:metadate>
</ui:define>

With the following template

<f:view>
    <ui:insert name="metadata"/>
    ...
</f:view>
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
  • D'oh! You are so right and surely earned the credit. The event listener is working fine, now. Unfortunately, the still doesn't seem to have any effect (locationBean.id is always 0 when preRenderView is called). Any ideas on that? – cg. Jul 27 '11 at 13:58