我是从Java动态添加复合组件并将对象作为cc attr传递,
代码段:
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);
}
如果我将对象作为 cc attr 传递,我看到StackOverflowError
。
请帮我找出我做错了什么。
以下是我收到的例外情况:
java.lang.StackOverflowError的
在
com.sun.faces.context.FacesContextImpl.assertNotReleased(FacesContextImpl.java:701)
在
com.sun.faces.context.FacesContextImpl.getAttributes(FacesContextImpl.java:237)
在
com.sun.faces.component.CompositeComponentStackManager.getManager(CompositeComponentStackManager.java:103)
在
com.sun.faces.facelets.el.ContextualCompositeValueExpression.pushCompositeComponent(ContextualCompositeValueExpression.java:266)
在
com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:156)
在
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
在
javax.faces.component.UIComponentBase $ AttributesMap.get(UIComponentBase.java:2409)
在
com.sun.faces.el.CompositeComponentAttributesELResolver $ ExpressionEvalMap.get(CompositeComponentAttributesELResolver.java:393)
在
javax.el.MapELResolver.getValue(MapELResolver.java:196)