Gibt es einen Bereich wie JSF @ViewScoped
in Spring 3.0? Ich habe eine Anwendung mit JSF + Spring, wo Backing-Beans von Spring verwaltet werden. Ich habe im Frühjahr keinen Bereich wie JSF gesehen. Ich sah den Blog Porting JSF 2.0’s ViewScope to Spring 3.0, aber es hat nicht für mich funktioniert.JSF View scope in Spring
Hier ist mein Versuch, auf dem benutzerdefinierten Frühling -umfang:
import java.util.Map;
import javax.faces.context.FacesContext;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;
/**
* Implements the JSF View Scope for use by Spring. This class is registered as a Spring bean with the CustomScopeConfigurer.
*/
public class ViewScope implements Scope {
public Object get(String name, ObjectFactory<?> objectFactory) {
System.out.println("**************************************************");
System.out.println("-------------------- Getting objects For View Scope ----------");
System.out.println("**************************************************");
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) {
System.out.println("**************************************************");
System.out.println("-------------------- View Scope object Removed ----------");
System.out.println("**************************************************");
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;
}
}
application-context.xml
:
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="view">
<bean class="com.delta.beans.ViewScope"/>
</entry>
</map>
</property>
</bean>
Dieser Beitrag von mir kann helfen: http://StackOverflow.com/q/12884822/1055089 – Vrushank
Ja, aber die Implementierung funktioniert nicht in meinem Code – khan
können Sie bitte den Code eingeben ?? Ich habe das gleiche in meiner App verwendet und es hat funktioniert. Ich benutze JSF2 + Spring 3 auch ... – Vrushank