The app I'm working on has to do some dynamic UIComponent creation. Something like
questionPanel = (HtmlPanelGrid) facesContext.getApplication().createComponent(HtmlPanelGrid.COMPONENT_TYPE);
where facesContext is injected.
For my unit tests, I'm using a simple mock Application:
public class MockApplicationExtension extends MockApplication {
@Override
public UIComponent createComponent(String name) throws FacesException {
if (name.equals(HtmlOutputLabel.COMPONENT_TYPE))
return new HtmlOutputLabel();
if (name.equals(HtmlOutputText.COMPONENT_TYPE))
return new HtmlOutputText();
if (name.equals(HtmlInputText.COMPONENT_TYPE))
return new HtmlInputText();
if (name.equals(HtmlPanelGrid.COMPONENT_TYPE))
return new HtmlPanelGrid();
return null;
}
@Override
public ValueBinding createValueBinding(String valueExpression) throws ReferenceSyntaxException {
return null;
}
}
I can't use this in integration tests, however. SeamTest doesn't provide a nice way to override the built-in MockApplication (that I can see).
Could SeamTest be altered to let me hook into the instantiation of the application field?
Or could MockApplication be extended to do some basic component creation, as I've done above? (maybe this wouldn't work well; I haven't thought about it much)
Also, if anyone has any pointers on how to work with dynamic UIComponent creation/binding in Seam, I'd love to hear them. I'm mostly going off this article:
http://technology.amis.nl/blog/?p=1187 I'm not sure if Seam provides a better way to do it.
Thanks