use of jakarta.faces.component.UINamingContainer in project myfaces by apache.
the class FaceletViewDeclarationLanguage method getComponentMetadata.
/**
* retargetMethodExpressions(FacesContext, UIComponent) has some clues about the behavior of this method
*
* {@inheritDoc}
*/
@Override
public BeanInfo getComponentMetadata(FacesContext context, Resource componentResource) {
BeanInfo beanInfo = null;
Assert.notNull(context, "context");
try {
Facelet compositeComponentFacelet;
FaceletFactory.setInstance(faceletFactory);
try {
compositeComponentFacelet = faceletFactory.getCompositeComponentMetadataFacelet(componentResource.getURL());
} finally {
FaceletFactory.setInstance(null);
}
// context.getAttributes().put(BUILDING_COMPOSITE_COMPONENT_METADATA, Boolean.TRUE);
// Create a temporal tree where all components will be put, but we are only
// interested in metadata.
UINamingContainer compositeComponentBase = (UINamingContainer) context.getApplication().createComponent(context, UINamingContainer.COMPONENT_TYPE, null);
// Fill the component resource key, because this information should be available
// on metadata to recognize which is the component used as composite component base.
// Since this method is called from Application.createComponent(FacesContext,Resource),
// and in that specific method this key is updated, this is the best option we
// have for recognize it (also this key is used by UIComponent.isCompositeComponent)
compositeComponentBase.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY, componentResource);
// According to UserTagHandler, in this point we need to wrap the facelet
// VariableMapper, so local changes are applied on "page context", but
// data is retrieved from full context
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
VariableMapper orig = faceletContext.getVariableMapper();
try {
faceletContext.setVariableMapper(new VariableMapperWrapper(orig));
compositeComponentBase.pushComponentToEL(context, compositeComponentBase);
compositeComponentFacelet.apply(context, compositeComponentBase);
compositeComponentBase.popComponentFromEL(context);
} finally {
faceletContext.setVariableMapper(orig);
}
beanInfo = (BeanInfo) compositeComponentBase.getAttributes().get(UIComponent.BEANINFO_KEY);
} catch (IOException e) {
throw new FacesException(e);
}
return beanInfo;
}
use of jakarta.faces.component.UINamingContainer in project myfaces by apache.
the class UIComponentFindComponentTest method testRelativeExpression.
public void testRelativeExpression() throws Exception {
String expression = "testimpl";
UIComponent namingContainer = new UINamingContainer();
UIComponent parent = new UIPanel();
namingContainer.setId("namingContainer");
namingContainer.getChildren().add(parent);
parent.setId("parent");
parent.getChildren().add(_testImpl);
_testImpl.setId("testimpl");
Assert.assertEquals(_testImpl, _testImpl.findComponent(expression));
}
use of jakarta.faces.component.UINamingContainer in project myfaces by apache.
the class UIComponentBaseGetClientIdTest method testWithParentNamingContainerChanging.
public void testWithParentNamingContainerChanging() throws Exception {
String id = "testId";
String containerClientId = "containerClientId";
for (int i = 0; i < 10; i++) {
final int j = i;
UIComponent namingContainer = new UINamingContainer() {
@Override
public String getContainerClientId(FacesContext ctx) {
return super.getContainerClientId(ctx) + j;
}
};
UIComponent parent = new UIPanel();
_testImpl.setId(id);
String expectedClientId = containerClientId + i + NamingContainer.SEPARATOR_CHAR + id;
namingContainer.setId(containerClientId);
namingContainer.getChildren().add(parent);
parent.setId("parent");
parent.getChildren().add(_testImpl);
Assert.assertEquals(expectedClientId, _testImpl.getClientId(facesContext));
Assert.assertEquals(expectedClientId, _testImpl.getClientId(facesContext));
parent.getChildren().remove(_testImpl);
}
}
use of jakarta.faces.component.UINamingContainer in project myfaces by apache.
the class CompositeComponentClientBehaviorTestCase method testSimpleClientBehaviorDefaultAjaxWrap.
@Test
public void testSimpleClientBehaviorDefaultAjaxWrap() throws Exception {
HelloWorld helloWorld = new HelloWorld();
facesContext.getExternalContext().getRequestMap().put("helloWorldBean", helloWorld);
UIViewRoot root = facesContext.getViewRoot();
vdl.buildView(facesContext, root, "testSimpleClientBehaviorDefaultAjaxWrap.xhtml");
UIComponent form = root.findComponent("testForm1");
Assert.assertNotNull(form);
UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
Assert.assertNotNull(compositeComponent);
UICommand button = (UICommand) compositeComponent.findComponent("button");
Assert.assertNotNull(button);
Assert.assertNotNull(button.getClientBehaviors().get("dblclick"));
Assert.assertEquals(1, button.getClientBehaviors().get("dblclick").size());
// StringWriter sw = new StringWriter();
// MockResponseWriter mrw = new MockResponseWriter(sw);
// facesContext.setResponseWriter(mrw);
// root.encodeAll(facesContext);
// sw.flush();
// System.out.print(sw.toString());
}
use of jakarta.faces.component.UINamingContainer in project myfaces by apache.
the class CompositeComponentClientBehaviorTestCase method testCompositeClientBehavior.
@Test
public void testCompositeClientBehavior() throws Exception {
HelloWorld helloWorld = new HelloWorld();
facesContext.getExternalContext().getRequestMap().put("helloWorldBean", helloWorld);
UIViewRoot root = facesContext.getViewRoot();
vdl.buildView(facesContext, root, "testCompositeClientBehavior.xhtml");
UIComponent form = root.findComponent("testForm1");
Assert.assertNotNull(form);
UINamingContainer compositeComponent = (UINamingContainer) form.getChildren().get(0);
Assert.assertNotNull(compositeComponent);
UINamingContainer compositeComponent2 = (UINamingContainer) compositeComponent.findComponent("button3");
Assert.assertNotNull(compositeComponent2);
UICommand button = (UICommand) compositeComponent2.findComponent("button");
Assert.assertNotNull(button);
// One added in testCompositeActionSource, the other one
// inside compositeActionSource.xhtml
Assert.assertNotNull(button.getClientBehaviors().get("action"));
Assert.assertEquals(1, button.getClientBehaviors().get("action").size());
// StringWriter sw = new StringWriter();
// MockResponseWriter mrw = new MockResponseWriter(sw);
// facesContext.setResponseWriter(mrw);
// root.encodeAll(facesContext);
// sw.flush();
// System.out.print(sw.toString());
}
Aggregations