views:

43

answers:

2

I'm performing a validation task that takes a while and am spinning the validation process into a separate thread. I've got the progress bar side of things working, with PortableRenderer and a ViewScope allowing it to update the progress bar component.

However, I'm trying to redirect the user once the page either finishes or a error in validation occurs, without the need of user interaction.

I'm using AND new to icefaces2.0(beta 1) and JSF 2.0, so the answer might be right in front of me. Sorry if this is a pretty simple question.

+1  A: 

Have ajax to execute this job rather than spawning a thread yourself.


Update as per the comments: well, that was a bit curt. But spawning a thread yourself inside a servletcontainer is recipe for major trouble if you don't know what you're doing. The functional requirement makes now a bit more sense. Your best bet is using IceFaces' push or poll component which in turn causes JavaScript in the client side to do a window.location on the desired URL.

BalusC
That's what I'd ideally do. But I need it fire off at browser load and report the progress back. It sounds like I need to learn jsf 2.0 and its Ajax tie ins. I'd rather use spring and jquery though but not my choice.
ClutchDude
See answer update. Btw: how would you do this in Spring/jQuery then? You can often just do the same in JSF flavor.
BalusC
I'd have the jquery hit a URL mapped by spring on page load to start it. Then have a loop poll it every 5 seconds until a spring returns a true. Not sure its the best way, but I think it'd work.
ClutchDude
IceFaces has a poll component. Sorry, can't go further in detail as I don't use IceFaces. I've only hands on experience with basic JSF impl and the Tomahawk and PrimeFaces component libraries.
BalusC
I checked into that polling component. Unfortunately, it's a Composite Component, which is only available if you pay for their subscription. (http://composite-component-showcase.icefaces.org/icefaces-composite-comps-showcase/showcase.iface) Too bad it fits the bill for this. I did look into the push mechanism as well(http://www.icefaces.org/main/ajax-java/ajaxpush.iface) but it already talks about using a renderer with a group, which is what I am doing. It sounds like I just need to send a request on page load so it gets handled by Icefaces, so that the renderer doesn't need to be portable
ClutchDude
A: 

I eventually fell back to my own way of doing it.

I'm putting the JSF bean into a session attribute with a portable renderer injected as a property. The session attribute is used since Spring cannot get the "View" scope. If there is a way for Spring to do so, that saves a lot of potential pitfalls, but alas I do not know how.

Once the page loads, a jquery AJAX call is made to a Spring Controller, which gets the JSF bean out of the session, removing it in the process, and proceeds to "validate it". As it proceeds, it sticks the current completion status into a session attribute and calls the bean function that invokes the portable renderer, which in turn updates the progress meter.

Also part of the page load function, is a separate function that calls another Spring Controller, which returns the completed status object, which may/may not have error messages.

I plan to remove the second controller by just checking values already on the page that get rendered by the portable renderer and publishing all those errors into the bean, which can then be rendered easily and dependably.

This way, as BalusC said, removes the creation of threads not directly spawned by the container and allows me to redirect automatically via window.location on successful completion.

If there is a better way to do this, which I imagine there is, please do add an answer. My knowledge with Icefaces and JSF is severely lacking currently and I'd thank anyone with the best way to do this.

ClutchDude