【问题标题】:PrimeFaces Wizard is not resetPrimeFaces 向导未重置
【发布时间】:2014-03-17 10:14:44
【问题描述】:

我们在 Tomcat 7 上使用 PrimeFaces 4.0 + spring 4。

我去 PrimeFaces 展示案例,打开向导,输入名字和姓氏并点击下一步按钮。然后我从左侧面板中选择其他菜单(例如 AutoComplete )我回到向导,名字和姓氏字段是清晰的。这正是我所期望的。

我开发了一个与上面相同的向导,但每次我回到向导页面时,向导仍然保持先前输入的值并且不会重置。

我的托管bean如下(我使用ViewScoped没有SessionScope在文档中提到):

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@Named
@ViewScoped
public class AccountController {

     @Valid
     private Account account = new Account()

     //Setters and getters    
}

已编辑:

我发现问题在于 JSF 和 Spring 的集成。当我删除 @Named 并使用 @ManagedBean 它工作正常。有cmets吗?!

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    Spring 没有对 JSF ViewScope 的内置支持,但您可以将此范围添加到 JSF:

    public class ViewScope implements Scope {
    
        public Object get(String name, ObjectFactory<?> objectFactory) {
            Map<String, Object> viewMap = FacesContext.getCurrentInstance()
                    .getViewRoot().getViewMap();
    
            if (viewMap.containsKey(name)) {
                return viewMap.get(name);
            } else {
                Object object = objectFactory.getObject();
                viewMap.put(name, object);
    
                return object;
            }
        }
    
        public Object remove(String name) {
            return FacesContext.getCurrentInstance().getViewRoot().getViewMap()
                    .remove(name);
        }
    
        public String getConversationId() {
            return null;
        }
    
        public void registerDestructionCallback(String name, Runnable callback) {
            // Not supported
        }
    
        public Object resolveContextualObject(String key) {
            return null;
        }
    }
    

    请参考http://blog.primefaces.org/?p=702

    在你的applicationConetext.xml

    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
        <property name="scopes">
            <map>
            <entry key="view">
                    <bean class="utils.ViewScope" />
            </entry>
            </map>
        </property>
    </bean>
    

    最后:

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ViewScoped;
    
    @Named
    @ViewScoped
    @Scope("view")
    public class AccountController {
    
         @Valid
         private Account account = new Account()
    
         //Setters and getters    
    }
    

    【讨论】:

    • @ViewScoped 现在是虚拟的,不需要。
    猜你喜欢
    • 2014-07-07
    • 1970-01-01
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    相关资源
    最近更新 更多