【问题标题】:a4j:commandLink not working when inside a lista4j:commandLink 在列表中时不起作用
【发布时间】:2011-12-24 06:10:25
【问题描述】:

参考这个问题 h:commandLink not working when inside a list

我的应用程序中遇到了同样的问题。我想尝试一个 ViewScoped bean,但由于使用 Spring 2.0 我没有机会将我的 bean 放入 View Scope。任何其他解决方法,我都可以尝试。

如果你能给我一个提示就好了。

【问题讨论】:

    标签: java richfaces jsf-1.2 ajax4jsf


    【解决方案1】:

    您可以将视图范围移植到spring:

    package com.yourdomain.scope;
    
    import java.util.Map;
    import javax.faces.context.FacesContext;
    import org.springframework.beans.factory.ObjectFactory;
    import org.springframework.beans.factory.config.Scope;
    
    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;
        }
    }
    

    在spring配置文件中注册新的作用域

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

    然后将它与你的 bean 一起使用

    @Component
    @Scope("view")
    public class MyBean {
    
        ...
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多