-1
內Reffering這個問題 h:commandLink not working when inside a listA4J:當列表
我有同樣的問題在我的應用commandLink不能正常工作。我想嘗試一個ViewScoped bean,但是導致使用Spring 2.0我沒有機會將我的bean放入View Scope。任何其他解決方法,我可以嘗試。
如果你能給我一個提示,那會很好。
內Reffering這個問題 h:commandLink not working when inside a listA4J:當列表
我有同樣的問題在我的應用commandLink不能正常工作。我想嘗試一個ViewScoped bean,但是導致使用Spring 2.0我沒有機會將我的bean放入View Scope。任何其他解決方法,我可以嘗試。
如果你能給我一個提示,那會很好。
您可以端口視圖範圍春:
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 {
...
}