2013-08-05 2 views
2

PopupViews에서 다음과 같은 문제가 발생했습니다. 내 응용 프로그램에 UI에 오류 처리기가 설정되어 있으며이 오류 처리기는 오류 이벤트를 받으면 Notification.show (...)를 호출하여 오류 알림을 표시합니다. 팝업보기에는 몇 가지 작업을 수행하는 버튼이 있습니다. 단추를 클릭하면 팝업보기가 닫히고 (setPopupVisible (false)를 호출하여) 작업이 실행됩니다. 그러나 작업이 실행되지 않고 예외가 throw되는 경우 예외가 UI에서 처리되고 화면에 오류 메시지가 표시 될 것으로 예상됩니다. 아쉽게도 핸들러는 오류 이벤트를 수신하고 Notification.show를 호출하지만 메시지는 표시되지 않습니다.PopupView를 닫고 같은 요청으로 알림을 표시하는 방법?

누군가 비슷한 문제에 직면 했습니까?

답변

1

다른 알림 시스템을 사용하고 비동기 JavaScript 코드를 실행할 수 있습니다. 은 또한 당신이 noty2 예를 을 위해 10 분 (angel이라는 AbstractJavaScriptComponent를 구현)에 다른 알림 시스템을 포장 할 수 있습니다 (사용하는 것이 포함되어야한다 jQuery를 lib 디렉토리) : 당신이 행동과 같이 실행될 때 NOTIF http://needim.github.io/noty/ 및 표시 :

 new Notty("WARNING<br>description... (static)", Notty.Type.WARNING).show(UI.getCurrent()); 
     new Notty("WARNING<br>description... (close in 3000ms)", Notty.Type.WARNING, 3000).show(UI.getCurrent()); 
     new Notty("WARNING<br>description... (modal)", Notty.Type.WARNING, 0, true).show(UI.getCurrent()); 
     new Notty("WARNING<br>description... (modal force, close in 3000ms)", Notty.Type.WARNING, 3000, true, true).show(UI.getCurrent()); 
     new Notty("asd", Notty.Type.ERROR, 5000).show(UI.getCurrent()); 

 package user_interface.util.ext; 

     import com.vaadin.annotations.JavaScript; 
     import com.vaadin.ui.AbstractJavaScriptComponent; 
     import com.vaadin.ui.AbstractOrderedLayout; 
     import com.vaadin.ui.UI; 
     import java.io.Serializable; 
     import java.util.Iterator; 

     public class Notty implements Serializable { 

      private String message; 
      private String type; 
      private int closeIn = 0; 
      private boolean force = false; 
      private boolean modal = false; 

      public Notty(String message, Notty.Type type) { 
       this.message = message; 
       this.type = type.value; 
      } 

      public Notty(String message, Notty.Type type, int closeIn) { 
       this.message = message; 
       this.type = type.value; 
       this.closeIn = closeIn; 
      } 

      public Notty(String message, Notty.Type type, int closeIn, boolean modal) { 
       this.message = message; 
       this.type = type.value; 
       this.closeIn = closeIn; 
       this.modal = modal; 
      }  

      public Notty(String message, Notty.Type type, int closeIn, boolean modal, boolean force) { 
       this.message = message; 
       this.type = type.value; 
       this.closeIn = closeIn; 
       this.modal = modal; 
       this.force = force; 
      } 

      public void show(UI ui) { 

       AbstractOrderedLayout aol = (AbstractOrderedLayout) ui.getContent(); 

       NottyMessage nm = null; 
       boolean wasAdded = false; 
       Iterator itr = aol.iterator(); 
       while(itr.hasNext()) { 
        Object o = itr.next(); 
        if (o instanceof NottyMessage) { 
         nm = (NottyMessage) o; 
         wasAdded = true; 
        } 
       } 

       if (!wasAdded) { 
        nm = new NottyMessage(); 
        aol.addComponent(nm);    
       } 

       nm.show(message, type, closeIn, force, modal); 
      } 

      @JavaScript({"NottyMessage.js"}) 
      private class NottyMessage extends AbstractJavaScriptComponent { 

       public NottyMessage() { 
        setImmediate(true); 
       } 

       @Override 
       protected NottyMessageState getState() { 
        return (NottyMessageState) super.getState(); 
       }   

       private void show(String mess, String type, int closeIn, boolean force, boolean modal) { 
        callFunction("show", mess, type, closeIn, force, modal); 
       } 

      } 

      public static enum Type { 

       ALERT("alert"), 
       INFORMATION("information"), 
       ERROR("error"), 
       WARNING("warning"), 
       NOTIFICATION("notification"), 
       SUCCESS("success"); 

       private String value; 

       private Type(String val) { 
        this.value = val; 
       } 
      } 

     } 

NottyMessageState.java

 package user_interface.util.ext; 

     import com.vaadin.shared.ui.JavaScriptComponentState; 

     public class NottyMessageState extends JavaScriptComponentState { 
      public String xhtml; 
      public String type; 
     } 

NottyMessage.js

 user_interface_util_ext_Notty_NottyMessage = function() { 

      var e = this.getElement(); 

      this.onStateChange = function() { 
       // change state callb 
      } 

      this.show = function(message, messageType, closeInMs, isForce, isModal) { 
       var n = noty({ 
        text: message, 
        type: messageType, 
        dismissQueue: true, 
        timeout: closeInMs, 
        force: isForce, 
        modal: isModal, 
        maxVisible: 7, 
        layout: "bottomLeft", 
        theme: "defaultTheme" 
       }); 
      } 

     } 

은 다음과 같아야합니다

noty2 jQuery plugin in Vaadin7 UI

0

아마 핸들러는 다른 스레드에서가 아니라 UI 스레드입니다. 나는 사용할 때까지 작동하지 않는 비활성화 버튼을 활성화하려고하는 이상한 행동을했습니다.

Button button = new Button("foo") 

// ... 

getUI().access(new Runnable(){ 
    public void run() { 
    button.setEnabled(true) 
    } 
}) 
관련 문제