1

I'd like close a dialog after one big process in my back bean. I tried some many things and now I am tried. I want leave a message to the user that the process is keeping going and,of course, show a progressbar n process and close it after take some minutes...simple. Normal approach... but doesn't work. I leave my code to explain better ...

    public void sendPush() {
            //validacitions...
            requestContext.execute("PF('dlg1').show()");//work well...we can see the dialog with the process
            myProcess();

        }

public void myProcess() {

//simulation only...here will be like 1 minute 
        Thread one = new Thread() {
            public void run() {
                try {
                    Thread.sleep(4000);
                } catch(InterruptedException v) {
                    System.out.println(v);
                }
                requestContext.execute("PF('dlg1').hide()");//here is the problem...don't close the dialog but when I debug the process pass here
                System.out.println("pass here");
            }

        };

        one.start();


    }

2 Answers2

1

First of it's not advised to spawn thread in a managed bean. See this.

Secundo the new thread as no reference to the requestContext I think. That is why it doesn't close the dialog.

So have your managed bean call a service :

@Named
@RequestScoped
public class Mymngedbean{
   @EJB
    private SomeService ss;

    public void yourmethod(){
         ss.asyncTask(RequestContext.getCurrentInstance());
    }

Your service:

@Stateless
public class SomeServiceImpl implements SomeService  {

    @Asynchronous
    public void asyncTask(RequestContext context) {
        // ...
        context.execute("PF('dlg1').hide()");
    }
}

Addind a thread might not be necessary though.

Community
  • 1
  • 1
Ced
  • 15,847
  • 14
  • 87
  • 146
0

You could use the AjaxStatus, if you dont need realtime interaction, and instant progression

Nassim MOUALEK
  • 4,702
  • 4
  • 25
  • 44