a4j:commandLink在列表中不起作用

时间:2011-11-08 08:12:31

标签: java richfaces jsf-1.2 ajax4jsf

对此问题的反对意见 h:commandLink not working when inside a list

我的应用程序中存在同样的问题。我想尝试使用ViewScoped bean,但是因为使用Spring 2.0我没有机会将我的bean放入View Scope。任何其他解决方法,我都可以尝试。

如果你能给我一个提示,那会很好。

1 个答案:

答案 0 :(得分:0)

您可以将视图范围移植到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;
    }
}

在弹簧配置文件中注册新范围

<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 {

    ...

}
相关问题