Sunday, June 9, 2013

Cyclic reference error in ManagedBean

I hope this wasn't an accident. I have a managed bean A and a managed bean B referencing each other just like code shown below:
   @ManagedBean(name="BeanA")
   @SessionScoped
   public class ManagedBeanA {
      
      @ManagedProperty(value="#{BeanB}")
      private ManagedBeanB beanB;
   }

   @ManagedBean(name="BeanB")
   @SessionScoped
   public class ManagedBeanB {
      
      @ManagedProperty(value="#{BeanA}")
      private ManagedBeanA beanA;
   }
Notice that the code shown above have cause cyclic reference in between BeanA and BeanB. This problem will not show until BeanA is get invoke by the server and following stacktrace will be thrown.
Caused by: javax.faces.el.EvaluationException: javax.el.ELException: javax.el.ELException: Detected cyclic reference to managedBean BeanA
     at org.apache.myfaces.el.convert.ValueExpressionToValueBinding.getValue(ValueExpressionToValueBinding.java:169)
     at org.apache.myfaces.config.impl.digester.elements.ManagedProperty.getRuntimeValue(ManagedProperty.java:120)
     at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:328)
     at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:169)
     at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
     at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
     at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
     at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
     at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
     at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:116)
     at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55)
     at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
     at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71)
     at org.apache.el.parser.AstValue.getValue(AstValue.java:149)
     at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283)
     at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:106)
     ... 40 more

No comments: