Create and render custom component using invokeOnComponent
Hi everyone,
I'm trying to through an AJAX request, caught by a PhaseListener hooked up after the RESTORE_VIEW phase, add a new component to the component tree and then re-render it's parent by using invokeOnComponent. Im trying to do this in the sort of fashion Jacob Hookom describe in one of his blog entries posted almost exactly one year ago.
http://weblogs.java.net/blog/jhook/archive/2006/02/new_feature_for.html
I'm running a glassfish V2. Everything seems to work fine all the way up to the actual rendering of the parent component. I have tried using encodeAll from the component but ending up with a NullPointerException being thrown at me. Jacob is in his code snipet using renderAll. Is this something else? If it is, then where is it and how do I use it?
Here is a snippet of my code:
This is parts of my AJAX handler inside the PhaseListener...
...
UIViewRoot root = context.getViewRoot();
String criteriaID = req.getParameter("criteriaID");
boolean found = root.invokeOnComponent(context, criteriaID, RENDER);
if (!found)thrownew FacesException(criteriaID +" not found!");
...
This is the callback...
publicstaticfinal ContextCallback RENDER =new ContextCallback(){
publicvoid invokeContextCallback(FacesContext context, UIComponent criteria){
Application app = context.getApplication();
StubComponent stubComp = (StubComponent)app.createComponent(StubComponent.COMPONENT_TYPE);
stubComp.setRendererType(StubComponent.RENDERER_TYPE);
stubComp.setId(context.getViewRoot().createUniqueId());
stubComp.setStubType("combo");
criteria.getChildren().add(stubComp);
criteria.encodeAll(context);
}
};
Have I missed anything important or does anyone have a working snippet of code that can partially render the component tree?
I am very very thankful for any help I can receive.
/Johan

