【问题标题】:Webflow view-state model bean properties are not autowiredWebflow 视图状态模型 bean 属性不是自动装配的
【发布时间】:2015-02-15 11:32:16
【问题描述】:

我有一个使用 JSF2 进行视图渲染的 Spring 3.2.11 和 Webflow 2.4.0 应用程序。

我的一个页面使用视图状态模型 bean 进行验证,但是当调用 validatePasswordChange 方法时,没有自动装配 bean 属性,所以我得到了 NPE。我不明白为什么它们是空的!?

感谢您的任何建议。

这是我的 bean 验证方法。为什么 passwordService 属性为空?

public void validatePasswordChange(ValidationContext context) {

    MessageContext messages = context.getMessageContext();
    if (!confirmPassword.equals(newPassword)) {

        messages.addMessage(new MessageBuilder().error()
                .source("confirmPassword")
                .defaultText(
                        this.getMessage("kyn.password.change.validation.noMatch"))
                .build());
    };

    List<String> validationMessages = passwordService
            .validatePasswordPolicyCompliance(getUsername(),
            newPassword);
    if (validationMessages != null) {
        for (String message : validationMessages) {
            messages.addMessage(new MessageBuilder().error()
                    .source("confirmPassword")
                    .defaultText(message).build());
        }
    }
}

这是我的 flow.xml 中的一个 sn-p。我在启动时将 passwordUpdateBean 插入 flowScope 并期望模型属性使用它:

<on-start>
    <evaluate expression="passwordUpdateBean" result="flowScope.passwordUpdateBean"></evaluate>
</on-start>

<view-state id="passwordChange" model="passwordUpdateBean">
    <transition on="proceed" to="update"/>
    <transition on="cancel" to="redirectCancel"  validate="false"/>
</view-state>

这是我的 bean 配置 xml:

<bean id="passwordUpdateBean"
    class="com.xyz.PasswordUpdateBean"
    scope="prototype"
    parent="abstractWebBean">
    <property name="passwordService" ref="passwordManagementService"/>  
    <property name="appUserDetailsService" ref="appUserDetailsService"/>
    <property name="autoLoginAfterEnrollment" value="true"/>
    <property name="usernamePasswordAuthenticationProvider" ref="usernamePasswordAuthenticationProvider"/>
</bean>

【问题讨论】:

    标签: spring-webflow-2


    【解决方案1】:

    bean 不会在您的流程定义中自动连接。您必须将 bean 显式检索到流定义中。

    注意@Service类注解可以在流文件(i.e &lt;evaluate expression="myService.getPasswordUpdateBean()" result="flowScope.passwordUpdateBean"/&gt;)中自动访问

    <on-start>
        <evaluate expression="....getPasswordUpdateBean()" result="flowScope.passwordUpdateBean"></evaluate>
        <!-- where '....' = either @service class or some other obj that holds a reference to the bean you seek --> 
    </on-start>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-15
      • 2015-04-17
      • 2014-11-05
      相关资源
      最近更新 更多