大进程命令按钮jsf后关闭对话框

时间:2015-08-25 15:01:30

标签: multithreading jsf primefaces javabeans

我希望在我的后台bean中执行一个大进程后关闭一个对话框。我尝试了很多东西,现在我尝试了。我想给用户留下一个信息,即该过程正在继续,当然,显示一个进度条n进程并在花费几分钟后将其关闭......简单。正常方法......但不起作用。我留下我的代码来解释更好......

    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 个答案:

答案 0 :(得分:1)

首先不建议在托管bean中生成线程。请参阅this

将新线程设为secundo,因为我认为没有对requestContext的引用。这就是它不关闭对话框的原因。

所以你的托管bean调用服务:

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

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

您的服务:

@Stateless
public class SomeServiceImpl implements SomeService  {

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

虽然可能没有必要添加一个线程。

答案 1 :(得分:0)

如果您不需要实时交互和即时进展,您可以使用AjaxStatus