1

I am using Spring for my DI. Is there an equivalent of @ManagedProperty? I want to inject the value from one view scoped bean into another one on the next page.

e.g

@Component
@Scope("view")
public class Page1Bean(){
   private String value;
}

@Component
@Scope("view")
public class Page2Bean(){
    @ManagedProperty(value = #{page1Bean}")  //doesnt work in Spring
    private Page1Bean bean;
}
DD.
  • 21,498
  • 52
  • 157
  • 246

1 Answers1

1

@Resource or @Autowired should work. @Resource is the Java EE implementation, @Autowired is the spring specific annotation. I can't find the reference now, but it seems like I read once to prefer @Resource over @Autowired.

here's a blog post I found that talks about @Inject vs. @Resource vs. @Autowired http://blogs.sourceallies.com/2011/08/spring-injection-with-resource-and-autowired/#more-2350

kolossus
  • 20,559
  • 3
  • 52
  • 104
digitaljoel
  • 26,265
  • 15
  • 89
  • 115
  • I believe this will instantiate a new Page1Bean..I want to pass along the actual Page1Bean with all its contents. – DD. Jan 02 '13 at 22:25
  • I've been using @Inject..I think thats JEE version. – DD. Jan 02 '13 at 22:26
  • for porting jsf view scope to spring: http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/ – digitaljoel Jan 02 '13 at 22:28
  • It shouldn't create a new Page1Bean unless one doesn't exist in the given scope. Since you aren't using one of the known scopes from Spring that may be why you believe it will instantiate a new Page1Bean. – digitaljoel Jan 02 '13 at 22:33
  • I've already ported view scope. View scope only exists on the current view. If you navigate to another page the bean will not be in scope and will be recreated. I've tested this using the post construct method. – DD. Jan 03 '13 at 05:24