में स्कोप देखें स्प्रिंग 3.0 में जेएसएफ @ViewScoped
जैसे कोई गुंजाइश है? मेरे पास जेएसएफ + स्प्रिंग का उपयोग करके एक एप्लीकेशन है जहां बैकिंग बीन्स स्प्रिंग द्वारा प्रबंधित किए जाते हैं। मुझे स्प्रिंग में जेएसएफ व्यू स्कोप की तरह कोई गुंजाइश नहीं मिली। मैंने ब्लॉग Porting JSF 2.0’s ViewScope to Spring 3.0 देखा, लेकिन यह मेरे लिए काम नहीं करता था।जेएसएफ स्प्रिंग
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>
मेरा यह पोस्ट सहायता कर सकता है: http://stackoverflow.com/q/12884822/1055089 – Vrushank
हाँ लेकिन कार्यान्वयन मेरे कोड – khan
में काम नहीं कर रहा है क्या आप कोड पोस्ट कर सकते हैं ?? मैंने अपने ऐप में इसका इस्तेमाल किया और यह काम किया। मैं जेएसएफ 2 + स्प्रिंग 3 का भी उपयोग कर रहा हूं ... – Vrushank