我正在使用带有自定义视图范围的Spring来创建视图范围bean。这工作正常,直到我尝试使用setPropertyActionListener注入属性。如果我将bean更改为请求范围,这可以正常工作。
这是我的观点范围:
public class ViewScope implements Scope {
public Object get(String name, ObjectFactory<?> objectFactory) {
if (FacesContext.getCurrentInstance().getViewRoot() != null) {
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;
}
} else {
return null;
}
}
public Object remove(String name) {
if (FacesContext.getCurrentInstance().getViewRoot() != null) {
return FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove(name);
} else {
return null;
}
}
public void registerDestructionCallback(String name, Runnable callback) {
// Do nothing
}
public Object resolveContextualObject(String key) {
return null;
}
public String getConversationId() {
return null;
}
}
和我的JSF:
<h:commandLink action="confirm.xhtml">
<f:setPropertyActionListener target="#{quoteHolder.item}" value="#{quote}"/>
</h:commandLink>