2

I am adding a composite component dynamically from Java and passing an object as the cc attr,

Code Snippet:

FacesContext context = FacesContext.getCurrentInstance();

Application application = context.getApplication();
FaceletContext faceletContext= 
(FaceletContext)context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);

Resource resource = application.getResourceHandler().createResource(resourceName);
UIComponent composite = application.createComponent(context, resource);
composite.setId("mycomp");

UIComponent implementation = application.createComponent(UIPanel.COMPONENT_TYPE);
implementation.setRendererType("javax.faces.Group");
composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME,implementation);
Map<String, String> valueExpressions = new HashMap<String, String>();
CustomObject obj = new CustomObject();    
valueExpressions.put("customobj", "#{obj}");

ELContext ctx = context.getELContext();
ValueExpression expr;
for (Map.Entry<String, String> entry : valueExpressions.entrySet()) {
   expr = factory.createValueExpression(ctx, entry.getValue(),Object.class);
   composite.setValueExpression(entry.getKey(), expr);
}

parent.getChildren().add(composite);
parent.pushComponentToEL(context, composite);
try {
    faceletContext.includeFacelet(implementation, resource.getURL());
} catch (Exception e) {
    throw new FacesException(e);
} finally {
    parent.popComponentFromEL(context);
}

I am seeing StackOverflowError if I pass object as cc attr.

Please help me to find what I am doing wrong.

Below is the exception I received:

java.lang.StackOverflowError at
com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:701) at com.sun.faces.context.FacesContextImpl.getAttributes(FacesContextImpl.java:237) at
com.sun.faces.component.CompositeComponentStackManager.getManager(CompositeComponentStackManager.java:103) at com.sun.faces.facelets.el.ContextualCompositeValueExpression.pushCompositeComponent(ContextualCompositeValueExpression.java:266) at com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:156) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2409) at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.get(CompositeComponentAttributesELResolver.java:393) at javax.el.MapELResolver.getValue(MapELResolver.java:196)

Coder
  • 21
  • 2
  • Which of the calls you posted above is repeated in the _StackOverflowError_ stack trace? – McDowell Mar 07 '14 at 12:56
  • While debugging I found that the exception occurs after the call to 'parent.popComponentFromEL(context);'. Could not see the call from my class in the exception. – Coder Mar 07 '14 at 13:24
  • Which Java are you using? 7 or 8? And please also add the exact version of JSF – alfonx Oct 20 '14 at 15:05

0 Answers0