2011-11-08 3 views
-1

안에 내 응용 프로그램에서 같은 문제가이 질문 h:commandLink not working when inside a listA4J : 목록

에 참고로하는 것에 때 CommandLink는 작동하지 않습니다. ViewScoped bean을 시도하고 싶지만, Spring 2.0을 사용하면 Bean을 View Scope에 배치 할 기회가 없다. 다른 해결 방법은 시도 할 수 있습니다.

나에게 힌트를 줄 수 있다면 좋을 것이다.

답변

0

당신은 포트 봄에 뷰 범위 수 있습니다

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> 

을 새로운 범위를 등록하고 콩보다 것은 그것을 사용

@Component 
@Scope("view") 
public class MyBean { 

    ... 

}