2

我已成功地将 JSF 与 Spring WebFlow 和 PrimeFaces 集成,但在我的 Web 流期间,@ManagedProperty 的注入始终为 NULL,但使用 @Autowired 注释注入有效。我想知道为什么@ManagedProperty 不起作用但@Autowired 起作用。

我的环境:Spring 3.2.1.RELEASE、JSF 2.2.4、PrimeFaces 3.0。

用户Bean类:

     @ManagedBean
     public class UserBean implements Serializable {

         @ManagedProperty(value="#{messageBean}")
         private MessageBean messageBean;

         public MessageBean getMessageBean() {
           return messageBean;
         }

         public void setMessageBean(MessageBean messageBean) {
           this.messageBean = messageBean;
         }
     }

消息豆类:

    @ManagedBean(name = "messageBean")
    public class MessageBean implements Serializable {
       public String getMessage(){
          return "Hello, " + name;
       }
    }

面孔-config.xml:

<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>

webflow.xml:

<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<flow-executor id="flowExecutor">
    <flow-execution-listeners>
        <listener ref="facesContextListener"/>
    </flow-execution-listeners>
</flow-executor>

<!-- The registry of executable flow definitions -->
<flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows">
    <flow-location-pattern value="/**/flow.xml" />
    <flow-location id="parent-flow" path="parent-flow.xml"/>
</flow-registry>

<!-- Configures the Spring Web Flow JSF integration -->
<faces:flow-builder-services id="flowBuilderServices" development="true" />

<!-- A listener to create and release a FacesContext -->
<beans:bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

我还有文件 flow.xml 和 view.xhtml,因为我已经使用 PrimeFaces 将 spring web flow 与 JSF 集成在一起。

WEB-INF/flows/ajax-jsf/flow.xml:

<var name="userBean"    class="org.springframework.samples.webflow.ajax.UserBean" />
<var name="messageBean" class="org.springframework.samples.webflow.ajax.jsf.MessageBean" />

<view-state id="view">
    <transition on="suggest" >
        <evaluate expression="userBean.createEmailSuggestion(flowRequestContext)"
            result="viewScope.emailSuggestion" />
    </transition>
</view-state>

你知道为什么我的@ManagedProperty 注入失败了吗?如果我用@Autowired 替换@ManagedProperty,我可以看到该对象已创建,但@ManagedProperty 始终为空。

4

0 回答 0