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

[2478 byte] By [jmalexa] at [2007-11-26 19:29:29]
# 1

Hi Johan,

Nothing jumps out as being wrong in your code. However, you might find it useful to look at Ed Burn's implementation of what you're trying to do. He also accounts for escaping CDATA sections, invoking multiple components, rendering multiple components, and many other features. You may decide you just want to use his project (Dynamic Faces).

You can find out more about it at:

https://jsf-extensions.dev.java.net

Or if you just want to look at the code:

https://jsf-extensions.dev.java.net/source/browse/jsf-extensions/trunk/code/run-time/avatar/src/main/java/com/sun/faces/extensions/avatar/components/

And of course, if you're not already... you may want to try Facelets (which I think has this feature builtin), or JSFTemplating which has Ed's implementation integrated and pre-installed.

Good luck!

Ken Paulsen

https://jsftemplating.dev.java.net

KenPaulsena at 2007-7-9 21:57:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for the answer!Very helpful, seems DynaFaces is exactly what I needed./Johan
jmalexa at 2007-7-9 21:57:59 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...