JSF, Spring, and the PreRenderViewEvent

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:48:37

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/6842330/jsf-spring-and-the-prerenderviewevent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!