-
1. Re: Display an StatusMessage from an Asynchronous method ?
kapitanpetko Nov 25, 2009 2:30 AM (in response to jeclic)Asynchronous methods don't have access to the session/conversation, so this will not work. You need to do polling on the client side or use something like RichFaces' <ajax:push> to notify the client.
HTH
-
2. Re: Display an StatusMessage from an Asynchronous method ?
jeclic Nov 25, 2009 11:57 AM (in response to jeclic)Ok thank you for your answer I had understood that async methods don't have access to the session/conversation but I had no idea how to handle that, ajax:push seams to be the right way.
Just another question : is it a normal behavior that when I call my asynchronous method from a
synchronous
method, I have to wait till the end of the async treatment to do something else on the web page ?Because I could display the message just before calling the async method...
Thank you
-
3. Re: Display an StatusMessage from an Asynchronous method ?
kapitanpetko Nov 25, 2009 1:18 PM (in response to jeclic)If you don't need the result form the asynchronous method, you don't have to wait for it to complete.
-
4. Re: Display an StatusMessage from an Asynchronous method ?
jeclic Nov 25, 2009 2:39 PM (in response to jeclic)Well I thought the same but I don't get it working with that code :
page.xhtml :
<s:button value="Start treatment" action="#{source.callAsynchronous(otherClass.instance)}" />
ISource.java :
@Local public interface ISourceFileManager { void callAsynchronous(); @Asynchronous void asynchronousMethod(); }
Source.java :
@Name("source") @Stateless public class Source implements ISource { @In private StatusMessages statusMessages; public void callAsynchronous(Param param) { this.statusMessages.add(Severity.INFO, "Treatment is being started"); asynchronousMethod(param); } public void asynchronousMethod(Param param) { // treatment } }
Do you see something wrong ?
Thank you -
5. Re: Display an StatusMessage from an Asynchronous method ?
kapitanpetko Nov 26, 2009 3:30 AM (in response to jeclic)For messages to be displayed, you need to submit the form. That doesn't happen with <s:button/>, use <h:commandButton/> instead.
Calling an asynchronous method from the same component generally doesn't work (it's not intercepted), so either have another component call it,
or use something like:Source source = (Source)Component.getInstance("source"); source.asynchronousMethod();
-
6. Re: Display an StatusMessage from an Asynchronous method ?
jeclic Nov 27, 2009 11:24 AM (in response to jeclic)I created a new component for my asynchronous method and it works well :-)
Thank you for you help.